<?php
$arr= array (
'supplier_id' => 1,
'filter_name' => array (
0 => 'product 1',
1 => 'Product 2',
2 => 'Product 3'
),
'quantity' => array
(
0 => 3,
1 => 10,
2 => 2
),
'unit' => array
(
0 => 'pkts',
1 => 'ltrs',
2 => 'pkts'
),
'price' => Array
(
0 => 11,
1 => 100,
2 => 10
),
'gross_amount' => Array
(
0 => 33,
1 => 1000,
2 => 20
),
'vat' => array
(
0 => 0,
1 => 0,
2 => 0
),
'net_amount' => array
(
0 => 33,
1 => 1000,
2 => 20
),
);
//echo "<pre>"; print_r($arr);
$i = 0;
$newArray = array();
do{
foreach($arr as $key=>$val){
if($key == 'supplier_id'){
$newArray[$key] = $val;
}else{
$newArray[$i][$key] = $val[$i];
}
}
$i++;
}while($i<3);
echo "<pre>"; print_r($newArray);
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
- <pre>Array
(
[supplier_id] => 1
[0] => Array
(
[filter_name] => product 1
[quantity] => 3
[unit] => pkts
[price] => 11
[gross_amount] => 33
[vat] => 0
[net_amount] => 33
)
[1] => Array
(
[filter_name] => Product 2
[quantity] => 10
[unit] => ltrs
[price] => 100
[gross_amount] => 1000
[vat] => 0
[net_amount] => 1000
)
[2] => Array
(
[filter_name] => Product 3
[quantity] => 2
[unit] => pkts
[price] => 10
[gross_amount] => 20
[vat] => 0
[net_amount] => 20
)
)
preferences:
64.55 ms | 410 KiB | 5 Q