fork download
  1. <?php
  2. // Multidimensional array
  3. $superheroes = array(
  4. "spider-man" => array(
  5. "name" => "Peter Parker",
  6. "email" => "peterparker@mail.com",
  7. ),
  8. "super-man" => array(
  9. "name" => "Clark Kent",
  10. "email" => "clarkkent@mail.com",
  11. ),
  12. "iron-man" => array(
  13. "name" => "Harry Potter",
  14. "email" => "harrypotter@mail.com",
  15. )
  16. );
  17.  
  18. // Printing all the keys and values one by one
  19. $keys = array_keys($superheroes);
  20. for($i = 0; $i < count($superheroes); $i++) {
  21. echo $keys[$i] . "{<br>";
  22. foreach($superheroes[$keys[$i]] as $key => $value) {
  23. echo $key . " : " . $value . "<br>";
  24. }
  25. echo "}<br>";
  26. }
  27. ?>
Success #stdin #stdout 0.03s 25832KB
stdin
Standard input is empty
stdout
spider-man{<br>name : Peter Parker<br>email : peterparker@mail.com<br>}<br>super-man{<br>name : Clark Kent<br>email : clarkkent@mail.com<br>}<br>iron-man{<br>name : Harry Potter<br>email : harrypotter@mail.com<br>}<br>