Loading…

How to use array_pop() and array_push() in PHP?

1. array_pop()

It is used to delete or remove the last element of an array.

Example

$a=array("blue","black","skyblue");
array_pop($a);

OUTPUT : Array ( [0] => blue[1] => black)

2. array_push()

It is used to Insert one or more elements to the end of an array.

Example

$a=array("apple","banana"); array_push($a,"mango","pineapple");

OUTPUT : Array ( [0] => apple[1] => banana[2] => mango[3] => pineapple)

Also Read: PHP Strings

Suggest An Answer

No suggestions avaliable!

Related Interview Questions