Both function doing same work add element in the array and Returns the number of elements in the new array.
So whats the difference ?
PHP Push Array – array_push()Add one or more elements onto the end of array. Returns the number of elements in the new array.
Standard method using array_push();
// create our array with 1 element
$arr = array("one");
// $count will be 3 and $arr will now be array("one","two","three");
$count = array_push($arr,"two","three");
PHP Unchift Array – array_unshift()
Add one or more elements to the beggining of an array. Returns the number of elements in the new array.
Standard method using array_unshift();
// create our array with 3 elements
$arr = array("three","four","five");
// $count will now be 5 and array will hold one - five
$count = array_unshift($arr,"one","two");
0 comments :
Post a Comment