Tsallaka zuwa abun ciki
Justice Tech School

Adding and Removing Items

array_push, array_pop, array_shift, array_unshift, unset and array_splice change arrays.

Example
$a = [1, 2, 3];
array_push($a, 4);
array_unshift($a, 0);
echo array_pop($a), array_shift($a), "\n";
unset($a[1]);
print_r(array_values($a));

Result

40
Array
(
    [0] => 1
    [1] => 3
)

Exercise

Remove last.

($a)

Quiz Test

What does array_shift remove?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.