This single line would do that:

$array = array_column($array, 'plan');

The first argument is an array | The second argument is an array key.

For details, go to official documentation: https://www.php.net/manual/en/function.array-column.php.

Answer from Usman Ahmed on Stack Overflow
🌐
Quora
quora.com › How-do-I-convert-a-two-dimensional-array-to-a-single-dimensional-array-in-PHP
How to convert a two-dimensional array to a single dimensional array in PHP - Quora
Answer (1 of 3): How to Flatten a Multidimensional Array? Turning multidimensional array into one-dimensional array [code]// 1 $result = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($myArray)), null); // 2 $a = array(1,2,array(3,4, array(5,6,7), 8), 9); $it = ne...
🌐
GitHub
gist.github.com › SeanCannon › 6585889
PHP array_flatten() function. Convert a multi-dimensional array into a single-dimensional array. · GitHub
<?php function array_flatten(array $multiDimArray): array { $flatten = []; $singleArray = array_map(function($arr) use (&$flatten) { $flatten = array_merge($flatten, $arr); }, $multiDimArray); return $flatten; } $multiDimArray = [[1, 2], [3, 4]]; print_r(array_flatten($multiDimArray)); /* Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) */
🌐
W3Docs
w3docs.com › php
Convert multidimensional array into single array
To convert a multidimensional array into a single array in PHP, you can use the array_merge() function.
🌐
Resource
shafiqul.wordpress.com › 2017 › 08 › 28 › convert-multidimensional-array-to-single-array-using-php
convert multidimensional array to single array using php | Resource
August 30, 2017 - <?php $your_array = array(0 => array('payment_id' => 3160), 1 => array('action' => 'update'), 2 => array('date' => '2017-05-17 09:59:40'), 3 => array('payment_date' => '23.05.201')); echo "<pre>"; print_r($your_array); $convert_array = array_reduce($your_array, 'array_merge', array()); echo "<pre>"; print_r($convert_array);
🌐
SitePoint
sitepoint.com › php
Convert Multidimensional array to single array - PHP - SitePoint Forums | Web Development & Design Community
April 26, 2014 - i want to convert multidimensional array to single array I am having this array array ( 0 => array ( 'sno' => 'q3', 'result' => '15', ), 1 => array ( 'sno' => 'q1', 'result' => '5', ), 2 => array ( 'sno' => 'q2', 'result' => '10', ), ) i want this resulting array array ( 'q3' => '15', 'q1' => '5','q2' =>'10' ) i tried foreach, but it gives the values (not an array ) like q3 15 q1 5 q2 10
🌐
Snipplr
snipplr.com › view › 67672 › php-convert-single-dimensional-array-to-two-dimensional
PHP Convert Single Dimensional Array to Two Dimensional - PHP Snipplr Social Repository
October 10, 2012 - Function to convert a one dimensional array to two dimensional with option to specify how many columns. Returns two dimensional array on success or false on fail. Expand | Embed | Plain Text · Copy this code and paste it in your HTML · <?php · $test = array(1,2,3,4,5,6,7,8,9); function array_2d($array, $col_count=2){ $result = false; if(!empty($array) && is_array($array)){ $row_count = ceil( count($array) / $col_count); $pointer = 0; for($row=0; $row < $row_count; $row++) { for($col=0; $col < $col_count; ++$col){ if(isset($array[$pointer])) { $result[$row][$col] = $array[$pointer]; $pointer++; } } } } return $result; } $result = array_2d($test, 3); echo '<pre>'.print_r($result, 1).'</pre>'; ?> Report this snippet Tweet ·
🌐
Edureka Community
edureka.co › home › community › categories › web development › php › how to convert multidimensional array into single...
How to convert multidimensional array into single array | Edureka Community
November 6, 2020 - I have an array which is multidimensional for no reason /* This is how my array is currently */ Array ( ... ] => newplan ) Any idea how to do this?
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-flatten-multidimentional-array-in-php
How to Flatten Multidimentional Array in PHP ? - GeeksforGeeks
July 11, 2024 - There are different approaches to flattening a multi-dimensional array, these are: ... The recursive approach involves traversing the nested arrays using recursion. It's a clean and flexible method that works well for arrays of any depth. ... <?php function flattenArray($arr) { $res = []; foreach ($arr as $val) { if (is_array($val)) { $res = array_merge($res, flattenArray($val)); } else { $res[] = $val; } } return $res; } // Driver code $arr = [1, [2, 3, [4, 5]], 6]; $flatArr = flattenArray($arr); print_r($flatArr); ?>
🌐
LinkedIn
linkedin.com › pulse › convert-multidimensional-array-single-ciro-attanasio
Convert multidimensional array in a single array
October 29, 2018 - Array ( [0] => 9 [1] => 4 [2] => 2 [3] => 3 [4] => 10 [5] => 11 [6] => 12 [7] => 8 [8] => 1 [9] => 5 [10] => 7 [11] => 6 ) ... I created a function called getChild($array_data, $finalItem = [] containing multi-dimensional array as argument.
🌐
Decodingweb
decodingweb.dev › flatten-array-php
How to flatten a multidimensional array in PHP (4 methods)
October 31, 2023 - If you have a two-dimensional array, you can flatten it by unpacking the array and passing it as an argument to the array_merge() function. <?php // Each array has two Apple devices in each category (iPads, phones, and laptops) $products = [ ...