ExpertRefresh

Array / Stacks  

Related Pages

Basics
Operations
Create
Key-value
Search
Modify
Pointer
Sort
Stacks
Randomize
Storage


0.0% 100%
 
 
0 pages 298 questions
1) Add element at the end of an array





2) Add element to the begining of an array





3) Extract the last element of an array




4) Remove the first element of an array







array_push() - add at end <?php // Example 1 $arr = array(); array_push($arr, 'bar', 'baz'); print_r($arr); // Array ( [0] => bar [1] => baz ) // Example 2 $arr[] = 'foo'; // when only one value if being pushed // faster than array_push (no function call) array_pop() - extract last element <?php $arr = array('bar', 'baz'); $lastIn = array_pop($arr); var_dump($lastIn, $arr); // string(3) "baz" array(1) { [0]=> string(3) "bar" } array_shift() - remove first <?php $arr = array('bar', 'baz'); $firstElement = array_shift($arr); //print_r($arr); // Array ( [0] => baz ) array_unshift() - add to begining <?php $arr = array('baz'); array_unshift($arr, 'foo'); print_r($arr); // Array ( [0] => foo [1] => baz )


References