<?php
$data = array(
'ID1' => array('Column 1', 'Cell 11', 'Cell 12', 'Cell 13'),
'ID2' => array('Column 2', 'Cell 21', 'Cell 22', 'Cell 23'),
'ID3' => array('Column 3', 'Cell 31', 'Cell 32'),
);
Foreach($data as $column){
$count[] = count($column);
}
$count = max($count);
For($i=1;$i<$count;$i++){
$arr["row" . $i] = array_column($data, $i);
}
Var_dump($arr);
- Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- array(3) {
["row1"]=>
array(3) {
[0]=>
string(7) "Cell 11"
[1]=>
string(7) "Cell 21"
[2]=>
string(7) "Cell 31"
}
["row2"]=>
array(3) {
[0]=>
string(7) "Cell 12"
[1]=>
string(7) "Cell 22"
[2]=>
string(7) "Cell 32"
}
["row3"]=>
array(2) {
[0]=>
string(7) "Cell 13"
[1]=>
string(7) "Cell 23"
}
}
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(3) {
["row1"]=>
array(3) {
[0]=>
string(7) "Cell 11"
[1]=>
string(7) "Cell 21"
[2]=>
string(7) "Cell 31"
}
["row2"]=>
array(3) {
[0]=>
string(7) "Cell 12"
[1]=>
string(7) "Cell 22"
[2]=>
string(7) "Cell 32"
}
["row3"]=>
array(2) {
[0]=>
string(7) "Cell 13"
[1]=>
string(7) "Cell 23"
}
}
preferences:
157.15 ms | 402 KiB | 158 Q