No, there is not a function to get your expected output natively, though you can make your own functions, just use array_column to get the types/column, and then loop over your array, on match remove the item as to not duplicate iterations.

Something like:

<?php
$data = [
    ['foodType' => 'fruits', 'itemID' => 1, 'itemName' => 'apple'],
    ['foodType' => 'fruits', 'itemID' => 2, 'itemName' => 'banana'],
    ['foodType' => 'veggies', 'itemID' => 3, 'itemName' => 'carrot'],
    ['foodType' => 'veggies', 'itemID' => 4, 'itemName' => 'broccoli']
];

function array_column_multi ($array, $column) {
    $types = array_unique(array_column($array, $column));

    $return = [];
    foreach ($types as $type) {
        foreach ($array as value) {
            if ($type === $value[$column]) {
                unset($value[$column]);
                $return[$type][] = $value;
                unset($array[$key]);
            }
        }
    }
    return $return;
}


print_r(array_column_multi($data, 'foodType'));

https://3v4l.org/KQVeN

Result:

Array
(
    [fruits] => Array
        (
            [0] => Array
                (
                    [itemID] => 1
                    [itemName] => apple
                )

            [1] => Array
                (
                    [itemID] => 2
                    [itemName] => banana
                )

        )

    [veggies] => Array
        (
            [0] => Array
                (
                    [itemID] => 3
                    [itemName] => carrot
                )

            [1] => Array
                (
                    [itemID] => 4
                    [itemName] => broccoli
                )

        )

)
Answer from Lawrence Cherone on Stack Overflow
🌐
PHP
php.net › manual › en › function.array-column.php
PHP: array_column - Manual
array_column implementation that works on multidimensional arrays (not just 2-dimensional): <?php function array_column_recursive(array $haystack, $needle) { $found = []; array_walk_recursive($haystack, function($value, $key) use (&$found, $needle) { if ($key == $needle) $found[] = $value; }); return $found; } Taken from https://github.com/NinoSkopac/array_column_recursive
Top answer
1 of 4
4

No, there is not a function to get your expected output natively, though you can make your own functions, just use array_column to get the types/column, and then loop over your array, on match remove the item as to not duplicate iterations.

Something like:

<?php
$data = [
    ['foodType' => 'fruits', 'itemID' => 1, 'itemName' => 'apple'],
    ['foodType' => 'fruits', 'itemID' => 2, 'itemName' => 'banana'],
    ['foodType' => 'veggies', 'itemID' => 3, 'itemName' => 'carrot'],
    ['foodType' => 'veggies', 'itemID' => 4, 'itemName' => 'broccoli']
];

function array_column_multi ($array, $column) {
    $types = array_unique(array_column($array, $column));

    $return = [];
    foreach ($types as $type) {
        foreach ($array as value) {
            if ($type === $value[$column]) {
                unset($value[$column]);
                $return[$type][] = $value;
                unset($array[$key]);
            }
        }
    }
    return $return;
}


print_r(array_column_multi($data, 'foodType'));

https://3v4l.org/KQVeN

Result:

Array
(
    [fruits] => Array
        (
            [0] => Array
                (
                    [itemID] => 1
                    [itemName] => apple
                )

            [1] => Array
                (
                    [itemID] => 2
                    [itemName] => banana
                )

        )

    [veggies] => Array
        (
            [0] => Array
                (
                    [itemID] => 3
                    [itemName] => carrot
                )

            [1] => Array
                (
                    [itemID] => 4
                    [itemName] => broccoli
                )

        )

)
2 of 4
1

Oh I just noticed that you're aggregating them by ID. There's not a function for that, you're going to need to iterate over the input with a loop, and populate an output array with the data you want. Eg:

$output = [];

foreach($input_array as $item) {
  $output[$item['id']][] = [
     'itemID' => $item['itemID'],
     'itemName' => $item['itemName']
  ];
}
🌐
Reintech
reintech.io › blog › a-complete-guide-to-php-array-column-function
A Complete Guide to PHP's `array_column()` Function
The array_column() function extracts values from a single column in a multi-dimensional array or array of objects.
🌐
MeshWorld
meshworld.in › tutorials › php › array_column
How to Get Values from Multi-dimensional Arrays with array_column() | MeshWorld
September 1, 2020 - array_column() is an inbuilt PHP function which is used to get the values from a single column from the multi-dimensional array or an array of objects.
🌐
Educative
educative.io › answers › what-is-the-arraycolumn-method-in-php
What is the array_column() method in PHP?
In PHP, we can use the array_column() method to create a column from a multidimensional array. It will return a single column from an array identified by the column’s key. We may also specify which keys will be used as an index for the new ...
🌐
W3Schools
w3schools.com › php › php_arrays_multidimensional.asp
PHP Multidimensional Arrays
PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people. A two-dimensional array is an array of arrays (a three-dimensional array ...
🌐
W3Schools
w3schools.com › php › func_array_column.asp
PHP array_column() Function
The array_column() function returns the values from a single column in the input array. ... <?php // An array that represents a possible record set returned from a database $a = array( array( 'id' => 5698, 'first_name' => 'Peter', 'last_name' ...
Find elsewhere
🌐
daily.dev
daily.dev › home › php dev › a complete guide to php's `array_column()` function
A Complete Guide to PHP's `array_column()` Function | daily.dev
October 2, 2025 - PHP's array_column() function extracts a single column from multi-dimensional arrays or arrays of objects. The function accepts an input array, a column key to extract, and an optional index key for the resulting array.
🌐
Scaler
scaler.com › home › topics › php array_column() function
PHP array_column() Function - Scaler Topics
April 1, 2024 - The array_column() function in PHP simplifies the extraction of specific columns from multi-dimensional arrays or recordsets.
🌐
ZetCode
zetcode.com › php-array › array-column
PHP array_column - Array Column Extraction in PHP
The PHP array_column function extracts a single column from a multi-dimensional array or an array of objects.
🌐
Reintech
reintech.io › blog › php-arrays-advanced-techniques-multidimensional-arrays
PHP Arrays: Advanced Techniques and Multidimensional Arrays
April 28, 2023 - The array_column() function extracts a single column from a multidimensional array, perfect for data analysis or preparing inputs for other functions:
🌐
Coddy.Tech
coddy.tech › docs › php › multidimensional arrays
PHP Multidimensional Arrays: Nested Arrays and Loops | Coddy
3 weeks ago - PHP multidimensional arrays with runnable examples: 2D arrays, arrays of rows, nested foreach, HTML tables, array_column, sorting rows and safe deep reads.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-multidimensional-array-search-by-value
PHP multidimensional array search by value - GeeksforGeeks
July 11, 2025 - This function only returns the key index instead of a search path. The array_column() function returns the values from a single column in the input array. Example: ... <?php // PHP program to carry out multidimensional array search // ...
🌐
Certbolt
certbolt.com › home › php multidimensional arrays explained with examples
PHP Multidimensional Arrays Explained with Examples - Certbolt | IT Certification News
May 13, 2026 - PHP’s extensive library of array ... array_column function is particularly useful for extracting all values of a specific named field from a two-dimensional array of associative records, producing a flat array of just those values....
🌐
CodeSignal
codesignal.com › learn › courses › multidimensional-arrays-and-their-traversal-in-php › lessons › multidimensional-arrays-and-their-traversal-in-php
Multidimensional Arrays and Their Traversal in PHP
PHP offers simple functions such as count() to manage multidimensional arrays and determine the number of rows (floors) and columns (units on each floor):
🌐
Yahubaba
yahubaba.com › php › php-multidimensional-array
PHP Multidimensional Array
<?php $emp = [ [1,"Krishana","Manager",50000], [2,"Salman","Salesman",20000], [3,"Mohan","Computer Operator",12000], [4,"Amir","Driver",5000] ]; echo "<pre>"; print_r($emp); echo "</pre>"; /* TWO dimensional Array row and column */ echo $emp[0][0] . " "; echo $emp[0][1] . " "; echo $emp[0][2] . " "; echo $emp[0][3] . " "; /* Multidimensional Array For Loop */ for ($row = 0; $row < 4; $row++) { for ($col = 0; $col < 4; $col++) { echo $emp[$row][$col] .