I have tried to echo out an image from an array, but it did not work.
$productArr = [
"PT" => [
"cat" => [ "image" => "cat.jpg", "desc" => "blah blah"],
"fish"=> [ "image" => "fish.jpg", "desc" => "blah blah"],
"dog" => [ "image" => "dog.jpg","desc" => "blah blah"],
],
"KC" => [
"Ice" => [ "image" => "ice.jpg", "desc" => "mah mah mah"],
"cold"=> [ "image" => "cold.jpg", "desc" => "mah mah mah"],
"water"=> [ "image" => "water.jpg", "desc" => "mah mah mah"],
],
];
$featuredArr = [
"KC" => "Ice",
"PT" => "cat",
];
foreach ($featuredArr as $key => $value) {
if ($productArr[$key][$value]) {
echo "key $key=>$value exists: <br />";
foreach ($productArr[$key][$value] as $newKey => $newValue) {
echo "$newKey['image']<br />";
}
}
}
I also want it to echo out Both "KC" and "PT" from $featuredArr. currently only "Cat" is being outputted.
echo "$newKey['image']<br />";should beecho "{$newKey['image']}<br />";. How is it running at all?$newKeyis a string, not an array.