2 つの配列:
//数组aarray ( 'SU13080800340' => array ( 0 => 'CVT121015001', 1 => 'CVT121015002', 2 => 'CVT121226001', ),)//数组barray ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00',)
array ('0' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015001',),'1' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015002',),'2' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121016001',),)
ポスターはあなたのニーズをより明確に説明する必要があります
例に従って書くだけの場合 コード展開すると問題が発生する可能性があります
あなたの例によれば、次のように書くことができます:
//数组a$a = array ( 'SU13080800340' => array ( 0 => 'CVT121015001', 1 => 'CVT121015002', 2 => 'CVT121226001' ));//数组b$b = array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00');$res = array();foreach($a['SU13080800340'] as $key=>$each){ $res[] = $b; $res[$key]['packageno'] = $each;}var_export($res);
array ( 0 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015001', ), 1 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015002', ), 2 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '3', 'total' => '48', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121226001', ),)
ポスター、あなたのニーズをより明確に説明する必要があります
単に使用例に従って書く場合コードは記述されていますが、展開時に問題が発生する可能性があります。
配列 a に対応する packageno の結果が示されています。 配列 b は cust_no に従ってグループ化されたデータです。
//数组aarray ( 'SU13080800340' => array ( 0 => 'CVT121015001', 1 => 'CVT121015002', 2 => 'CVT121226001', ),)//数组barray ('0' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '1', 'total' => '16', 'c1_time' => '2013-08-10 15:00:00',),'1' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5B', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00',),)
array ('0' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '1', 'total' => '16', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015001',),'1' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015002',),'2' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121016001',),)
2 つの配列間の接続をどのように決定するのかわかりません
//数组a$a = array ( 'SU13080800340' => array ( 0 => 'CVT121015001', 1 => 'CVT121015002', 2 => 'CVT121226001', ),);//数组b$b = array ('0' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '1', 'total' => '16', 'c1_time' => '2013-08-10 15:00:00',),'1' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5B', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00',),);foreach($b as $item) { for($i=0; $i<$item['mount_total']; $i++) { $item['packageno'] = current(array_splice($a[$item['stock_no']], 0, 1)); $res[] = $item; }}var_export($res);
array ( 0 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '1', 'total' => '16', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015001', ), 1 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5B', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015002', ), 2 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5B', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121226001', ),)
//数组a$a = array ( 'SU13080800340' => array ( 0 => 'CVT121015001', 1 => 'CVT121015002', 2 => 'CVT121226001', ),);//数组b$b = array ('0' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '1', 'total' => '16', 'c1_time' => '2013-08-10 15:00:00',),'1' =>array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5B', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00',),);foreach($b as $item) { for($i=0; $i<$item['mount_total']; $i++) { $item['packageno'] = current(array_splice($a[$item['stock_no']], 0, 1)); $res[] = $item; }}var_export($res);
array ( 0 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5A', 'mount_total' => '1', 'total' => '16', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015001', ), 1 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5B', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121015002', ), 2 => array ( 'stock_no' => 'SU13080800340', 'adress' => 'B', 'arr_time' => '2013-08-14 09:00:00', 'c_type' => 'P32E', 'cust_no' => '310F61VA5B', 'mount_total' => '2', 'total' => '32', 'c1_time' => '2013-08-10 15:00:00', 'packageno' => 'CVT121226001', ),)
これは彼が挙げた単なる具体例だと思います... 配列 A と B を判断する方法はありません正確な順序に対応するのは、この種の関係です...
この関係はハードコーディングされています。ありがとう!