Guest User

Untitled

a guest
Jun 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. <?php
  2. //Associative arrays in PHP
  3. // and the foreach method
  4.  
  5. $arr = array('Rob', 'Bob', 'Robert', 'Bobby', 'Mr. Paulson');
  6.  
  7. $assoc = array('Brad'=>'Tyler Durden', 'Ed'=>'The narrator', 88 => 'Five', 'Helena'=>'Marla Singer');
  8. $assoc[] = 'Robert Paulson';
  9.  
  10. //foreach($arr as $k => $name){
  11. foreach($arr as $nm){
  12. //echo $k . ' - ' . $name . '<br/>';
  13. echo $nm . '<br/>';
  14. }
  15.  
  16. foreach($assoc as $key => $name){
  17. echo $key . ' - ' . $name . '<br/>';
  18. }
  19. ?>
Add Comment
Please, Sign In to add comment