Its the first time I am working with a 3-dimensional array, maybe its just a syntax erorr which I can't find, but I guess its something else - so I am asking you. This is my PHP array which I want to loop thru. At the moment it has only one element at its highest index for testing purposes:
<?
$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
)
)
);
?>
How I try to check the amount of my packages (which should be one?):
require_once("inc/packages.php");
if(isset($packages)) echo "ok";
else echo "not ok";
This outputs me: "Not ok".
I would probably use a foreach
:
foreach($packages as $package) {
var_dump($package);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.