循环通过3dimensional数组

时间:2015-02-01 20:47:45

标签: php arrays

这是我第一次使用三维数组,也许它只是一个我无法找到的语法错误,但我想其他的东西 - 所以我问你。这是我想要循环的PHP数组。目前,为了测试目的,它只有一个元素处于最高指数:

<?
$packages = array(
    "package1" => array (
        "EUW" => array (
            "id" => 1,
            "imgsrc" => "images/packages/background01.jpg",
            "title" => "blabla",
            "desc" => "blabla",
            "level" => 15,
            "rp" => 16975,
            "ip" => 40000,
            "price" => 35,
            "soldout" => true
        ),
        "EUNE" => array (   
            "id" => 1,
            "imgsrc" => "images/packages/background01.jpg",
            "title" => "blabla",
            "desc" => "blabla",
            "level" => 15,
            "rp" => 16975,
            "ip" => 40000,
            "price" => 35,
            "soldout" => true
        ),
        "NA" => array ( 
            "id" => 1,
            "imgsrc" => "images/packages/background01.jpg",
            "title" => "blabla",
            "desc" => "blabla",
            "level" => 15,
            "rp" => 16975,
            "ip" => 40000,
            "price" => 35,
            "soldout" => true
        ),
        "BR" => array ( 
            "id" => 1,
            "imgsrc" => "images/packages/background01.jpg",
            "title" => "blabla",
            "desc" => "blabla",
            "level" => 15,
            "rp" => 16975,
            "ip" => 40000,
            "price" => 35,
            "soldout" => true
        ),
        "LAN" => array (    
            "id" => 1,
            "imgsrc" => "images/packages/background01.jpg",
            "title" => "blabla",
            "desc" => "blabla",
            "level" => 15,
            "rp" => 16975,
            "ip" => 40000,
            "price" => 35,
            "soldout" => true
        )
    )
);
?>

我如何尝试检查我的包裹数量(应该是一个?):

require_once("inc/packages.php");
if(isset($packages)) echo "ok";
else echo "not ok";

这导致我:“不行”。

1 个答案:

答案 0 :(得分:0)

我可能会使用foreach

foreach($packages as $package) {
   var_dump($package);
}