Array Functions

There are numerous built-in functions for array manipulation.

count()

Use count to get the total number of values in your array.

12

array_count_values()

Use array_count_values() to count the occurences of a specific value.

Array ( [Chips] => 3 [Cheese] => 1 [Apples] => 1 [Bananas] => 1 [Cake] => 1 )

implode

The implode() function is used to turn an array into a string.  It accepts an array value and a separator.

I love to eat Chips and Cheese and Apples and Bananas and Chips and Cake and Chips.

explode

The explode() function does the reverse of imploder() and its used to turn a string into an array.  It accepts a string and separator.

Array ( [0] => I [1] => love [2] => to [3] => eat [4] => chips )

array_pop()

The array_pop() is used to remove the last element from an array.

Array ( [0] => orange [1] => banana [2] => apple [3] => raspberry )
Array ( [0] => orange [1] => banana [2] => apple )
Popped fruit is (raspberry)

array_push()

The array_push() is used to add a new element add the end of an array.

Array ( [0] => orange [1] => banana )
Array ( [0] => orange [1] => banana [2] => apple [3] => raspberry )