Use Foreach, While And List To Loop Through Associate Array

 
    <?php
$characters = array(
        array(
        "name" => "A",
        "occupation" => "A1",
        "age" => 30,
        "special power" => "A3"
        ),
        array(
        "name" => "B",
        "occupation" => "B1",
        "age" => 24,
        "special power" => "B2"
        ),
        array(
        "name" => "C",
        "occupation" => "C1",
        "age" => 45,
        "special power" => "C2"
        )
      );foreach ($characters as $c) {
        while (list($k, $v) = each ($c)) {
                echo "$k ... $v <br/>";
        }
}?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.