Given an array as follow :
$z = [
"cat lovers" => [
"name" => "cat lovers",
"impressions" => 2038,
"ctr" => 0.032875368007851,
"actions" => [
[
"action_type" => "attention_event",
"value" => "232",
],
[
"action_type" => "landing_page_view",
"value" => "18",
],
],
"shorty kodi" => [
"name" => "shorty kodi",
"impressions" => 534,
"ctr" => 0.041198501872659,
"actions" => [
[
"action_type" => "attention_event",
"value" => "56",
],
[
"action_type" => "landing_page_view",
"value" => "7",
]
]
]
Following code run with no error :
foreach($z as $i) {
print_r(array_column($i["actions"], "action_type"));
}
But if we remove the print_r function to like :
foreach($z as $i) {
$b = array_column($i["actions"], "action_type");
}
It results an error saying :
PHP error: Undefined index: actions on line 2
Any idea why?
Thanks