Linked Questions
136 questions linked to/from Transposing multidimensional arrays in PHP
12 votes
4 answers
4k views
How to create an associative array from two arrays? [duplicate]
I have two arrays one for keys and another for values. The values array is an array of array. Keys array: $keyArray = array("clientId","clientName","clientAdsress","clientPhone"); Values array: $...
7 votes
2 answers
6k views
create transpose matrix using php [duplicate]
For example if a matrix is: 1 2 3 4 5 6 Then transpose of above matrix will be: 1 3 5 2 4 6 This is my current code: <?php // transpose matrix $trans = array( array(1, 2), ...
11 votes
3 answers
5k views
Is there better way to transpose a PHP 2D array? [duplicate]
According to the PHP Manual, calling array_map with a NULL callback causes it to perform a "zip" function, creating an array of arrays of parallel elements from the given arrays. For example: ...
7 votes
4 answers
8k views
Transpose rows and columns in a 2D array [duplicate]
I have created a table that displays a series of numbers in a table. I am trying to transpose the matrix (flip rows and columns) using a for each loop and a function named transpose_matrix but it ...
3 votes
3 answers
2k views
Swap first level keys and second levels keys of a 2d array [duplicate]
I am trying to seperate some value by key. My current array like this Array ( [name] => Array ( [0] => test1 [1] => test2 ) [type] => ...
3 votes
6 answers
2k views
Transpose 2d array with inconsistent column structure [duplicate]
Array ( [0] => Array ( [color] => Brown ) [1] => Array ( [color] => Green ) [2] => Array ( [...
1 vote
3 answers
4k views
Combine and transpose three arrays with associative keys [duplicate]
I have three arrays for instance Array1 array (size=3) 0 => string 'a' (length=1) 1 => string 'b' (length=1) 2 => string 'c' (length=1) Array2 array (size 3) 0 => string '$' (length=1) 1 ...
1 vote
7 answers
10k views
loop to populate html table vertically [duplicate]
I have a mysql query that returns an array of rows. How would i populate my html table using php vertically? there is no limit to how many columns i my HTML table allowed. My MYSQL query returns ...
1 vote
2 answers
4k views
displaying a mysql table vertically - for comparison or for print out purposes [duplicate]
Say you got a table view like this seed_id name country ------- ---------- ------- 1 John America 2 Jose Mexico 3 Khan ...
2 votes
5 answers
4k views
Combine 3 or more arrays (php) [duplicate]
Quick example: $array_1 = [1, 2, 3]; $array_2 = ['a', 'b', 'c']; $array_3 = ['white', 'red', 'blue']; I need an array like: $array_4 = [ [1, 'a', 'white'], [2, 'b', 'red'], [3, 'c', 'blue'...
0 votes
2 answers
6k views
Transpose an array of objects [duplicate]
I have the array below: [1]=> array(2) { [0]=> object(stdClass)#23 (7) { ["AddressesTableID"]=> string(1) "8" ["AccreditNo"]=> string(13) "5129876de28ff" ...
1 vote
3 answers
4k views
PHP Loop Multidimensional Associative Array [duplicate]
I have this output: I don't have any idea how can I make my array look like this: $array[ 0 => [ 'item_id' => 6, 'price' => "2311.00", 'qty' => 12, '...
1 vote
2 answers
3k views
Elegant way to convert associative array into an indexed one [duplicate]
Having an associative array like $myarray = array ( 'user' => array ( 2 => 'john', 5 => 'done', 21 => 'foo' ), 'city' => array ( 2 => 'london', 5 ...
0 votes
5 answers
369 views
Transpose an associative array with indexed rows [duplicate]
I am getting this array when form is submitted array 'item' => array 0 => string 'Salt' 1 => string 'Pepper' 'quantity' => array (size=2) 0 => string '2 ...
1 vote
4 answers
1k views
How to change associative array value in php [duplicate]
$arr = array( 0 => array( 0 => 'one', 1 => 'two', 2 => 'three' ), 1 => array( 0 => 'sun', 1 => 'mon', 2 => 'tues' ...