Arrays |
| Use |
Syntax |
Example(s) |
| return the number of elements in an array | sizeof() | = array("apples", "oranges", "blue");echo "Array has " . sizeof() . " elements";(Returns 3) |
| Remove an element from the end of an array | array_pop() | array_pop();(removes the element from the end of the array ) |
| Add an element to the end of an array | array_push(, ) | array_push(, "Stuff");(adds "Stuff" to the end of array |
| remove an element from the beginning of an array. | array_shift() | array_shift() |
| add an element to the beginning of an array. | array_unshift(, ) | array_unshift(, "phone")(Adds 'phone' to the beginning of the array |
| reverse the order of elements in an array. | array_reverse() | ="one","two","three"(returns 'three,two,one') |
| input an array and return a new array containing only its values(not its keys) | array_values() | = array("one" => "taco", "two" => "burrito"); print_r(array_values());(outputs as an array[0] => taco [1] => burrito) |
| accept an array and return only its keys | array_keys() | = array("one" => "taco", "two" => "burrito"); print_r(array_keys()); (outputs as an array[0] => one [1] => two) |