Skip to content

Instantly share code, notes, and snippets.

@stemar
Last active March 27, 2026 23:59
Show Gist options
  • Select an option

  • Save stemar/84a0925a4262fd17ba4465e07d1d0a7b to your computer and use it in GitHub Desktop.

Select an option

Save stemar/84a0925a4262fd17ba4465e07d1d0a7b to your computer and use it in GitHub Desktop.

Revisions

  1. stemar revised this gist Mar 27, 2026. No changes.
  2. stemar revised this gist Jul 5, 2025. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions array_column.php
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    <?php
    if (!function_exists('array_column')) {
    function array_column(array $rows, $column_key, $index_key = NULL) {
    $array = array();
    foreach ($rows as $row) {
    function array_column(array $array, $column_key, $index_key = NULL) {
    $output = array();
    foreach ($array as $row) {
    if (is_null($index_key)) {
    $array []= is_null($column_key) ? $row : $row[$column_key];
    $output []= is_null($column_key) ? $row : $row[$column_key];
    }
    else {
    $array[$row[$index_key]] = is_null($column_key) ? $row : $row[$column_key];
    $output[$row[$index_key]] = is_null($column_key) ? $row : $row[$column_key];
    }
    }
    return $array;
    return $output;
    }
    }
  3. stemar created this gist Jun 29, 2025.
    15 changes: 15 additions & 0 deletions array_column.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?php
    if (!function_exists('array_column')) {
    function array_column(array $rows, $column_key, $index_key = NULL) {
    $array = array();
    foreach ($rows as $row) {
    if (is_null($index_key)) {
    $array []= is_null($column_key) ? $row : $row[$column_key];
    }
    else {
    $array[$row[$index_key]] = is_null($column_key) ? $row : $row[$column_key];
    }
    }
    return $array;
    }
    }