Memory App
Programming
 




Add to end

array_push() - add at end

$arr = array();

array_push($arr, 'bar', 'baz'); // [0] => bar [1] => baz

$arr[] = 'foo';

// when only one value if being pushed
// faster than array_push (no function call)
(1/4)

Remove last

array_pop() - extract last element

$arr = array('bar', 'baz');

$lastIn = array_pop($arr);

var_dump($lastIn, $arr);

// string(3) "baz" array(1) { [0]=> string(3) "bar" }
(2/4)

Remove first

array_shift() - remove first

$arr = array('bar', 'baz');

$firstElement = array_shift($arr); // [0] => baz
(3/4)

Add to begining

array_unshift() - add to begining

$arr = array('baz');

array_unshift($arr, 'foo'); // [0] => foo [1] => baza


Questions



Top Reference > Programming
0/0 (80)  
Not Logged