Home >Backend Development >PHP Tutorial >How can I Transform Multidimensional Column Data into Row Data Using array_column in PHP?
Restructuring Multidimensional Column Data into Row Data Using array_column
Some programming tasks, such as exchanging columns for rows in a multidimensional array, can be simplified with the right tools. In this case, the array_column function offers a straightforward solution.
To transform an associative array of column data into a multidimensional array of row data, follow these steps:
Here's the code to achieve this transformation:
<code class="php">$result = array(); foreach($where['id'] as $k => $v) { $result[] = array_column($where, $k); }</code>
The resulting array will now be structured as:
<code class="php">array( array(12, '1999-06-12'), array(13, '2000-03-21'), array(14, '2006-09-31') );</code>
which matches the desired output.
This method leverages the power of array_column, a built-in PHP function designed for such array manipulations. By combining iteration and column extraction, we can seamlessly transform the data into the desired format with ease.
The above is the detailed content of How can I Transform Multidimensional Column Data into Row Data Using array_column in PHP?. For more information, please follow other related articles on the PHP Chinese website!