Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught Error: Call to undefined function each()

I’m wondering if you guys can give me an idea about how to replace this each function:

while(list($key,$val) = each($_SESSION['cart'][$i]))
        {
            if ($key=="product_name"){
                $product_name=$val;
            }else if($key=="units"){
                $units=$val;
            }else if($key=="packing_size"){
                $packing_size=$val;
            }else if($key=="grade"){
                $grade=$val;
            }else if($key=="length"){
                $length=$val;
            }else if($key=="quantity"){
                $quantity=$val;
            }
        }
        echo $product_name."".$units."".$packing_size."".$grade."".$length."".$quantity;
        echo "<br>";
    }

Thanks!

I’ve try to use foreach, but isn’t working at all

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I assume your original question is "How to replace a deprecated loop with each()"…?
In this case ADyson’s commentary will be of great help to you.

But then why carry out tests on keys to obtain values ​​that you then place in variables that you only display…?
If you just want to display the values ​​you can access your array through the keys
As in the code below

foreach($_SESSION['cart'][$i] as $key => $val)
{
    echo $val["product_name"]."".$val["units"]."".$val["packing_size"]."".$val["grade"]."".$val["length"]."".$val["quantity"];
    echo "<br>";    
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading