Answer the question
In order to leave comments, you need to log in
What's wrong with php array parsing?
Please help me figure out the error:
Warning: Invalid argument supplied for foreach() in
$settings['menu'] = array(
0 => array(
"name" => "Dashbord",
"link" => "/dashbord/index",
"icon" => "fa fa-dashboard nav_icon",
"multimenu" => 0,
),
1 => array(
"name" => "Заказы",
"link" => "/order/all",
"icon" => "fa fa-shopping-basket nav_icon",
"multimenu" => array(
0 => array (
"name" => "Создать заказ",
"link" => "/order/add",
"icon" => "fa fa-shopping-basket nav_icon",
),
),
),
);
foreach ($arr as $parameter => $value) {
if($value['multimenu'] = 0) {
$this->genMenu = '<li><a href="'.$value['link'].'" class=" hvr-bounce-to-right"><i class="'.$value['icon'].'"></i><span class="nav-label">'.$value['name'].'</span></a></li>';
} else if($value['multimenu'] = 1) {
foreach ($arr[$parameter]['multimenu'] as $value) {
print_r($value['name']);
}
}
}
foreach ($arr[$parameter]['multimenu'] as $value) {
Answer the question
In order to leave comments, you need to log in
You don't have an equality check (==) in your if's, but an assignment (=). Accordingly, the first if will never work (the result of the assignment is the assigned value, and 0 is treated as false).
I recommend using the Yoda style, then there will be fewer such errors.if (0 == $value['multimenu'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question