Array Functions

count($myArray) ; //gives the number of indexes

 

unset($myArray[index]) ; //removes the element at index

 

unset($yourArray) ; //deletes the whole array

 

foreach () ; //iterates values in an array

 

foreach($myArray as $value) {

echo “The values are $value: \n”;

}

 

each($myArray) ; //returns a key/vale pair for each element in the array

 

array_push($myArray, $value) ; //pushes $value onto end of $myArray

 

*equivalent to: $myArray[] = $value ;

 

array_pop($myArray) ; //returns end value from the array, and removes the index, thus reducing the index length

 

array_unshift($myArray, $value) ; //inserts $value into index 0 and shifts all other indexes +1

 

array_shift($myArray) ; //removes index 0 and shifts all other indexes -1

 

print_r($myArray) ; //prints human-readable information about a variable

 

var_dump($myArray) ; //displays structured information about a variable including its type and value

*Arrays and objects are explored recursively with values indented to show structure.

 

sort($myArray) ; //sorts an array by its values. Assigns new keys!

 

Leave a Reply