3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $board = array( array( 0, 0, 0, 0, 0, 0, 0, 0 ), array( 0, 0, 1, 0, 0, 0, 0, 0 ), array( 0, 0, 0, 0, 0, 0, 0, 0 ), array( 0, 0, 0, 0, 0, 0, 0, 0 ), array( 0, 0, 0, 0, 0, 0, 0, 0 ), array( 0, 0, 0, 0, 0, 0, 0, 0 ), array( 0, 0, 0, 0, 0, 0, 0, 0 ), array( 0, 0, 0, 0, 0, 0, 0, 0 ), array( 0, 0, 0, 0, 0, 0, 0, 0 ), ); function array_column(array $input, $columnKey, $indexKey = null) { $array = array(); foreach ($input as $value) { if ( ! isset($value[$columnKey])) { trigger_error("Key \"$columnKey\" does not exist in array"); return false; } if (is_null($indexKey)) { $array[] = $value[$columnKey]; } else { if ( ! isset($value[$indexKey])) { trigger_error("Key \"$indexKey\" does not exist in array"); return false; } if ( ! is_scalar($value[$indexKey])) { trigger_error("Key \"$indexKey\" does not contain scalar value"); return false; } $array[$value[$indexKey]] = $value[$columnKey]; } } return $array; } echo array_sum(array_column($board, 2));
Output for 5.3.0 - 5.4.45
1