Previously there was such an array {code ...} to convert it into an array {code ...} could you tell me how to volist the array in the first format of ThinkPHP to the table in the view? Do you have any good solutions? Thank you ~ Once upon a time there was such an array
Array ([id] => Array ([0] => 500002-016 [1] => 500471-012) [name] => Array ([0] => domestic drug stent (made in China) [quota] [1] => disposable positive pressure needle-free connecting indwelling needle (made in China) [B 10%]) [specification] => Array ([0] => y [1] => x) [quantity] => Array ([0] => 22 [1] => 23 ))
Want to change to such an array
Array ([0] => Array ([id] => 500002-016 [name] => domestic drug stent (made in China) [quota] [specification] => y [quantity] => 22) [1] => Array ([id] => 500471-012 [name] => disposable positive pressure needle-less connector indwelling needle (made in China) [B 10%] [specification] => x [quantity] => 23 ))
Could you tell me how to volist the array in the first format of ThinkPHP to the table in the view? Do you have any good solutions? Thank you ~
Reply content:
Once upon a time there was such an array
Array ([id] => Array ([0] => 500002-016 [1] => 500471-012) [name] => Array ([0] => domestic drug stent (made in China) [quota] [1] => disposable positive pressure needle-free connecting indwelling needle (made in China) [B 10%]) [specification] => Array ([0] => y [1] => x) [quantity] => Array ([0] => 22 [1] => 23 ))
Want to change to such an array
Array ([0] => Array ([id] => 500002-016 [name] => domestic drug stent (made in China) [quota] [specification] => y [quantity] => 22) [1] => Array ([id] => 500471-012 [name] => disposable positive pressure needle-less connector indwelling needle (made in China) [B 10%] [specification] => x [quantity] => 23 ))
Could you tell me how to volist the array in the first format of ThinkPHP to the table in the view? Do you have any good solutions? Thank you ~
This is easy to understand.
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... The only method I have come up with 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' => $ data ['name'] [$ key], 'specification '=> $ data ['specification'] [$ key], 'quantity '=> $ data ['quantity'] [$ key]);} unset ($ data );
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' => $name[$i], 'specification' => $specification[$i], 'quantity' => $quantity[$i] ); } return $result;}