Tsallaka zuwa abun ciki
Justice Tech School

array_slice, merge and combine

array_slice takes a part, array_merge joins arrays, array_combine pairs keys and values and the + operator unions.

Example
$a = [1, 2, 3, 4];
print_r(array_slice($a, 1, 2));
print_r(array_merge([1], [2, 3]));
print_r(array_combine(["x", "y"], [1, 2]));

Result

Array
(
    [0] => 2
    [1] => 3
)
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
Array
(
    [x] => 1
    [y] => 2
)

Exercise

Join arrays.

array_([1], [2])

Quiz Test

Which pairs keys and values?

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