Wednesday 29 June 2016

PHP Array Type and Common PHP Array Function

PHP Array Types : 
An array is a special variable, which can hold more than one value at a time.
  • Indexed arrays - Arrays with a numeric index  => he index can be assigned automatically (index always starts at 0), like this:                                                                                         $cars = array("Volvo", "BMW", "Toyota");                                                                                                                                                                                  
  • Associative arrays - Arrays with named keys :Associative arrays are arrays that use named keys that you assign to them.                                                                                             $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");       foreach($age as $x => $x_value) {
        echo "Key=" . $x . ", Value=" . $x_value;
        echo "<br>";
    }                                                                                                                                                                                                                                                                                                                
  • Multidimensional arrays - Arrays containing one or more arrays
           A multidimensional array is an array containing one or more arrays.

          $cars = array(
           array("Volvo",22,18),
           array("BMW",15,13),
           array("Saab",5,2),
          array("Land Rover",17,15)
         );



PHP ARRAY FUNCTION :
1.array_key_exists("Volvo",$a)
2.array_flip()  Flips/Exchanges all keys with their associated values in an array
3.array_merge(array1,array2,array3...)
4.array_search("red",$a); return key 
5.in_array("Glenn", $people)
6.array_push($a,"blue","yellow");














No comments:

Post a Comment