数组关系求解

WBOY
Lepaskan: 2016-06-23 14:18:39
asal
1036 orang telah melayarinya

本帖最后由 lazygc520 于 2013-08-10 10:38:37 编辑

已知stock_no为SU13061301011对应26个packageno:
array(1) {  ["SU13061301011"]=>  array(26) {    [0]=>    string(15) "VP3.0 130219001"    [1]=>    string(15) "VP3.0 130219002"    [2]=>    string(15) "VP3.0 130219003"    [3]=>    string(15) "VP3.0 130219004"    [4]=>    string(15) "VP3.0 130219005"    [5]=>    string(15) "VP3.0 130219006"    [6]=>    string(15) "VP3.0 130219007"    [7]=>    string(15) "VP3.0 130219008"    [8]=>    string(15) "VP3.0 130219009"    [9]=>    string(15) "VP3.0 130219010"    [10]=>    string(15) "VP3.0 130219011"    [11]=>    string(15) "VP3.0 130219012"    [12]=>    string(15) "VP3.0 130219013"    [13]=>    string(15) "VP3.0 130219014"    [14]=>    string(15) "VP3.0 130219015"    [15]=>    string(15) "VP3.0 130219016"    [16]=>    string(15) "VP3.0 130219017"    [17]=>    string(15) "VP3.0 130219018"    [18]=>    string(15) "VP3.0 130219019"    [19]=>    string(15) "VP3.0 130219020"    [20]=>    string(15) "VP3.0 130219021"    [21]=>    string(15) "VP3.0 130219022"    [22]=>    string(15) "VP3.0 130219023"    [23]=>    string(15) "VP3.0 130219024"    [24]=>    string(15) "VP3.0 130219107"    [25]=>    string(15) "VP3.0 130219108"  }}
Salin selepas log masuk


另已知第一个stock_no对应13个packageno,第二个stock_no对应13个packageno:
$sql2 = "SELECT stock_no, cust_no, mount FROM `stock_detail` ORDER BY arr_time, adress, c_type ASC";$result2 = mysql_query($sql2);while($v2 = mysql_fetch_array($result2,MYSQL_ASSOC)){    var_dump($v2);}array(3) {  ["stock_no"]=  string(13) "SU13061301011"  ["cust_no"]=  string(10) "237033AW0A"  ["mount"]=  string(2) "13"}array(3) {  ["stock_no"]=  string(13) "SU13061301011"  ["cust_no"]=  string(10) "237033AW0A"  ["mount"]=  string(2) "13"}
Salin selepas log masuk


问题:如何让第一个stock_no对应前13个packageno,第二个stock_no对应后13个packageno?


回复讨论(解决方案)

while($v2 = mysql_fetch_array($result2,MYSQL_ASSOC)) {  $v2[] = array_splice($arr[$v2['stock_no']], 0, 13); //取出数组的前13项  var_dump($v2);}
Salin selepas log masuk

[/code]
$arr是指?

哦,了解。学习了!

1#
如果不止2组数据,像这样:

array(3) {  ["stock_no"]=>  string(13) "SU13061301016"  ["cust_no"]=>  string(10) "23703EX80A"  ["mount"]=>  string(1) "8"}array(3) {  ["stock_no"]=>  string(13) "SU13061301016"  ["cust_no"]=>  string(10) "23703EX80A"  ["mount"]=>  string(1) "7"}array(3) {  ["stock_no"]=>  string(13) "SU13061301016"  ["cust_no"]=>  string(10) "23703JX30A"  ["mount"]=>  string(1) "1"}array(3) {  ["stock_no"]=>  string(13) "SU13061301016"  ["cust_no"]=>  string(10) "23703JX30A"  ["mount"]=>  string(1) "2"}
Salin selepas log masuk


怎么进行分配?
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan