Updated on Kisan Patel
In this tutorial, we have hand-picked useful array functions that I think will be most useful for you in PHP.
array_push is the quickest way to add one or more items to the end of the array:
$friends = array("Kisan", "Ravi"); array_push($friends, "Devang"); var_dump($friends);
array_pop is the opposite of array_push: it pulls the last item off of the array and returns it.
$friends = array("Kisan", "Ravi"); array_pop($friends); // Delete Ravi from array var_dump($friends);
array_unshift function adds an item (or several) to the beginning of the array.
$friends = array("Kisan", "Ravi"); array_unshift($friends, "Devang", "Ujas"); var_dump($friends);
array_shift pulls the first item off the front of the array and returns it.
$friends = array("Kisan", "Ravi"); var_dump(array_shift($friends));
count function simply takes an array as a parameter and returns the total number of items there are in the array.
$friends = array("Kisan", "Ravi", "Devang", "Ujas", "Jay"); echo 'Number of friends: ' .count($friends);