PHP 11.7 : My weird solution

php

#1

I got the job done, but my solution seems a little weird to me. My array was an associative array where each index pointed to a regular array. I had to use a second foreach loop inside of the first one in order to echo all of the elements.

Is there a more straight-forward way? ...

Code:

    $myArray = array(
        "meats" => array("chicken", "beef", "pork"),
        "vegetables" => array("cucumber", "green pepper", "tomato")
    );

    echo $myArray["meats"][0] . "<br>";

foreach ($myArray as $class => $items) {
    echo $class . "<br>";
    foreach ($items as $item) {
        echo "  - " . $item . "<br>";
    }
}

#3

tnx buddy .......................................................................................