Wednesday, 28 January 2015

Add & Remove Value In Array



<?php
//array_push use to add element in an array :

// define an array
$myarray = array('element1', 'element2', 'element3');

// add an element to the end
array_push($myarray, 'element4');

print_r($myarray);


//print output Array ( [0] => element1 [1] => element2 [2] => element3 [3] => element4 )

//array_pop use to remove value from an array :

// define an array
$myarray = array('element1', 'element2', 'element3'); 

// remove an element from the end
array_pop($myarray); 

print_r($myarray); 


//print output Array ( [0] => element1 [1] => element2  )

?>

No comments: