Skip to content

Conversation

mmalferov
Copy link
Member

When performing a zip operation, keys of input arrays are ignored. The function only considers the sequential order of elements (as determined by their internal pointers), not their indices:

<?php

$a = [42 => 1, 'foo' => 2, '' => 3, 0 => 4, -4 => 5];
$b = [4 => 'one', 3 => 'two', 2 => 'three', 1 => 'four', 0 => 'five'];
$c = [-4 => 'uno', 0 => 'dos', '' => 'tres', 'foo' => 'cuatro', 42 => 'cinco'];

$d = array_map(null, $a, $b, $c);
print_r($d);

Output:

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => one
            [2] => uno
        )

    [1] => Array
        (
            [0] => 2
            [1] => two
            [2] => dos
        )

    [2] => Array
        (
            [0] => 3
            [1] => three
            [2] => tres
        )

    [3] => Array
        (
            [0] => 4
            [1] => four
            [2] => cuatro
        )

    [4] => Array
        (
            [0] => 5
            [1] => five
            [2] => cinco
        )

)

As we can see, the indexes were ignored

Keys of input arrays are ignored. The function only considers the sequential order of elements (as determined by their internal pointers), not their indices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant