Arrays in PHP


Array is a collection of data access and stored as a group and are normally access via index key.


  ex.: 


  $days = array(1=> 'mon', 'tue', 'wed', 'thurs', 'fri', 'sat', 'sun');


  • list created are index from 1 to 7
  • index number 1 points to the string value 'mon'

  

  ex.: 


  $mov = array('10' => 'casablance',    '9.65' => 'To kill a rat',     '2.35' => 'The English',    '8' => 'Traffic');



  • asort($mov), this will sort the description side of the array $mov
  • krsort($mov), this will sort the list via key index value

Array Convertion


  $array1 = explode( < separator>, < string> );

  $string1 = implode( < glue>, < array> );


  • explode, convert a string to a valid array
  • implode, convert an array to a string

  

ex.: 


  $str = 'mon-tue-wed-thur';

  $x1 = explode('-', $str);


  result: 


  $x1 = 'mon, tue, wed, thur';