Advertisement
touhid_xml

Looping multidimentional array using foreach loop in PHP

Sep 7th, 2015
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. $persons = [
  5.     ["name"=> "Anik Saha", "address"=> "Tangail, Bangladesh", "email"=> "anik@bangla-code.com"],
  6.     ["name"=> "Touhid", "address"=> "Dinajpur, Bangladesh", "email"=> "touhid@bangla-code.com"],
  7.     ["name"=> "Fie Chakrobarty", "address"=> "Panchagar, Bangladesh", "email"=> "fie@bangla-code.com"]
  8. ];
  9.  
  10. /**
  11. for($i=0;$i<count($persons); $i++){
  12. echo "Name: {$persons[$i]['name']}, Address: {$persons[$i]['address']}, Email: {$persons[$i]['email']}<br />\n";
  13. } **/
  14.  
  15. echo "<table border=\"1\">\n";
  16. echo "<tr><th>Name</th><th>Address</th><th>Email</th></tr>\n";
  17. foreach($persons as $person){
  18. echo "<tr><td>{$person['name']}</td><td>{$person['address']}</td><td>{$person['email']}</td></tr>\n";
  19. }
  20.  
  21. echo "</table>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement