×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: William Davies
Added: Dec 5, 2014 5:43 PM
Views: 18
Tags: no tags
Arrays are a good way to store several related items of data such personal details (name, address, DOB)
  1. Normal array
  2. $myGadgets = array('iMac', 'iPad', 'iPhone');
  3.  
  4. Shorthand array
  5. $myGadgets = ['iMac', 'iPad', 'iPhone'];
  6.  
  7. Associative array
  8. $myGadgets = array('computer'=>'iMac', 'tablet'=>'iPad', 'phone'=>'iPhone');
  9.  
  10. echo $myGadgets['phone']; (will output iPhone)
  11.  
  12. Append to an array
  13. $myGadgets[] = 'sounddock';
  14.  
  15. Examine contents and structure of array
  16. print_r($myGadgets);
  17.  
  18. Output a value from an array
  19. echo $myGadgets[1];
  20. (Will output 'iPad')
  21.  
  22. Convert entire array to string
  23. echo implode(', ', $myGadgets);
  24. (First argument is how you would like to seperate each element)