A
A
Alexander2017-10-06 11:02:54
PHP
Alexander, 2017-10-06 11:02:54

What's wrong with php array parsing?

Please help me figure out the error:

Warning: Invalid argument supplied for foreach() in

There is an array:
$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",
            ),
        ),
    ),
);

And there is array parsing:
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']);
                }
            }
        }

Actually, the cycle works and gives me the answer "name" => "Create order", but the error haunts me ..
Swears at the line:
foreach ($arr[$parameter]['multimenu'] as $value) {

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-10-06
@SmoKE_xD

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 question

Ask a Question

731 491 924 answers to any question