PHP 8.6.0 Alpha 2 available for testing

Voting

: max(three, two)?
(Example: nine)

The Note You're Voting On

Hiranmoy Chatterjee
4 years ago
The following function may be useful to create columns from all values of indexed arrays:

<?php
function array_column_all(array $arrays): array
{
    $output = [];
    $columnCount = count($arrays[0]);
    for ($i = 0; $i < $columnCount; $i++)
    {
        $output [] = array_column($arrays, $i);
    }
    return $output;
}
?>

Use:
-----
<?php
array_column_all(
    [
        ['A1', 'A2', 'A3'],
        ['B1', 'B2', 'B3'],
        ['C1', 'C2', 'C3'],
    ]
);
?>

This will output:
-------------------
Array
(
    [0] => Array
        (
            [0] => A1
            [1] => B1
            [2] => C1
        )

    [1] => Array
        (
            [0] => A2
            [1] => B2
            [2] => C2
        )

    [2] => Array
        (
            [0] => A3
            [1] => B3
            [2] => C3
        )

)

<< Back to user notes page

To Top