Array relationship solving

Source: Internet
Author: User
Array link solution This post was last edited by lazygc520 at 10:38:37

It is known that the value of stock_no is SU13061301011, which corresponds to 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"  }}


It is also known that the first stock_no corresponds to 13 packageno, and the second stock_no corresponds to 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"}


Q: How can I make the first stock_no correspond to the first 13 packageno and the second stock_no correspond to the last 13 packageno?


Reply to discussion (solution)

While ($ v2 = mysql_fetch_array ($ result2, MYSQL_ASSOC) {$ v2 [] = array_splice ($ arr [$ v2 ['stock _ no'], 0, 13 ); // retrieve the first 13 items of the array var_dump ($ v2 );}

[/Code]
$ Arr refers?

Oh, understand. Learning!

1 #
If there are more than two groups of data, such:

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"}


How to allocate?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.