Multidimensional array


#1

How can I loop through the array and output the contents to the browser? (using either "for loop" or "foreach" given that my multidimensional array is as follows)

EX) $myArray=array(array("apple",4),array("banana",6),array("coconut",2));


#2

For multidimensional arrays we need to use nested loops:

    $myArray = array(
        array("apple", 4),
        array("banana", 6),
        array("coconut", 2)
    );
    $c = count($myArray);
    for ($i = 0; $i < $c; $i++) {
          $l = count($myArray[$i]);
          for ($j = 0; $j < $l; $j++) {
              echo $myArray[$i][$j];
              echo "<br>";
        }
    }

#3

Thanks a lot for your quick help!
Good day!