Once there was such an array
Array ( [id] = = array ( [0] = 500002-016 [1] = 500471-012 ) [name] = = Array ( [0] = home-made drug stent (domestic) [limit] [1] = one-time positive pressure needle-free connection type indwelling needle (domestic) [B 10%] ) [specification] = = Array ( [0] = y [1] = X ) [Quantity] = = Array ( [0] = [1] = + ))
Want to become such an array
Array ( [0] = = Array ( [id] = 500002-016 [name] + le PU domestic drug stent (domestic) [Quota] [ specification ] = = y [quantity] [ 1] = = Array ( [id] = 500471-012 [name] = = One-time positive pressure needle-free connection type indwelling needle (domestic) [B 10%] [specification] + x [Quantity] [] =) )
Or ask Thinkphp's master. How to Volist an array of the first format to a table in the view what good way do you have?
Reply content:
Once there was such an array
Array ( [id] = = array ( [0] = 500002-016 [1] = 500471-012 ) [name] = = Array ( [0] = home-made drug stent (domestic) [limit] [1] = one-time positive pressure needle-free connection type indwelling needle (domestic) [B 10%] ) [specification] = = Array ( [0] = y [1] = X ) [Quantity] = = Array ( [0] = [1] = + ))
Want to become such an array
Array ( [0] = = Array ( [id] = 500002-016 [name] +-Domestic drug stent (domestic) [limit] [ specification] = > y [Quantity] = [ 1] = = Array ( [id] = 500471-012 [name] + = One-time positive pressure needle-free connection type indwelling needle (domestic) [B 10%] [specification] + x [Quantity] [] =) )
Or ask Thinkphp's master. How to Volist an array of the first format to a table in the view what good way do you have?
Easy to understand, I would write like this.
function Rebuild ($data) {$result = array (); $keys = Array_keys ($data); $num = count ($data [' id ']); for ($i = 0; $i < $num; + + $i) {$item = Array (), foreach ($keys as $key) {$item [$key] = $data [$key] [$i];} $result [] = $item;} return $result;}
This one... The only way I can think of is foreach.
function Arr_format ($arr) { $res = array (); foreach ($arr as $k + $v) { foreach ($v as $kk + = $VV) { $res [$KK] [$k] = $VV; } } return $res;}
$data = your data; $temp = array ();//Save the changed data foreach ($data [' id '] as $key = = $val) { Array_push ($temp, Array ( ' id ' = > $val, ' name ' and ' = ' $data [' name '] [$key], ' specification ' + $data [' specification '] [$key], ' Quantity ' = $data [' Quantity '] [$key]) );} Unset ($data);
Come in a different way if the field is fixed.
function Arr_format ($arr) { $result = array (); List ($id, $name, $specification, $quantity) = Array_values ($arr); for ($i = 0, $count = count ($id), $i < $count, $i + +) { $result [] = Array ( ' id ' = = $id [$i], ' name ' = = $na me[$i], ' specification ' = $specification [$i], ' quantity ' = $quantity [$i] ); } return $result;}