PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Last

Add element to end - array_push()
 
$arr = array();
array_push($arr, 'bar', 'baz');
$arr[] = 'foo'; // faster than array_push (no function call)

print_r($arr); // [bar, baz, foo]
Remove (extract) last element - array_pop()
 
$arr = array('bar', 'baz');
echo $lastIn = array_pop($arr); // baz

var_dump($arr); // [bar]

First

Remove first element - array_shift()
 
$arr = array('bar', 'baz');

echo $firstElement = array_shift($arr); // bar
Add element to beginning - array_unshift()
 
$arr = array('baz');
array_unshift($arr, 'foo');

print_r($arr); // [foo, baz]

Questions    
Array storage

        A B C D E F
🔔
1/4