Advertisement
humanware

php_training_day4_arrays

Aug 7th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2. /*
  3. ARRAYS
  4. Array is a complex type of variable which can store multiple amount of data in a single variable
  5.  
  6. TYPE OF ARRAYS
  7. 1. Index Array
  8.     An array with numeric key
  9. 2. Associative Array
  10.     an array where each key has it's own specific value
  11. 3. Multidimensional Array
  12.     An array containing one or more arrays within itself.
  13. */
  14.  
  15. // INDEX ARRAY OR NUMERIC ARRAY
  16. $colors = array('Red', 'Green', 'Blue', 'Orange');
  17. echo $colors[0];
  18.  
  19. echo '<br /><br /><br />';
  20.  
  21. // $colors[0] = 'Red';
  22. // $colors[1] = 'Green';
  23. // $colors[2] = 'Blue';
  24. // $colors[3] = 'Orange';
  25.  
  26. // Associative Array
  27. $ages = array('Peter' => 22, 'Marco' => 32, 'Josh' => 40);
  28. echo $ages['Peter'];
  29.  
  30. // $ages['Peter'] = 22;
  31. // $ages['Marco'] = 32;
  32.  
  33. echo '<br /><br /><br />';
  34.  
  35. $contacts = array(
  36.     array(
  37.         'name' => 'Peter Parker',
  38.         'email' => 'peterparker@gmail.com'
  39.     ),
  40.    
  41.     array(
  42.         'name' => 'Clark Kent',
  43.         'email' => 'clarkkent@gmail.com'
  44.     ),
  45.  
  46.     array(
  47.         'name' => 'Harry Potter',
  48.         'email' => 'harrypotter@gmail.com'
  49.     )
  50. );
  51.  
  52. echo $contacts[0]['name'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement