PHP array_column(),可能为空列

Does anybody know a way of getting a result of "5" from this this without using a for/foreach?

$array = [
    ['number1' => 1], 
    ['number1' => 1],
    ['number1' => 1], 
    ['number2' => 2], 
]

echo array_sum( array_column( $array, 'number1' ?? 'number2' ) );

I understand why my example does not work (the string 'number1' is never null).

If not, how much less performant would a for or a foreach be than using array_column?

If you want to always take the first item from the inner array regardless of its key, you can map reset to imitate array_column.

echo array_sum(array_map('reset', $array));

array_sum, as others have suggested, will also work, but if any of the inner arrays have more values that wouldn't give you the result you want.

Just for completeness sake this is the most performant way to achieve your desired result.

$total = 0;
foreach( $array as $sub_array )
{
    foreach( $sub_array as $value )
    {
        $total+= $value;
    }
}