Php array problems

Source: Internet
Author: User
Php array problems
Array (size = 3) 0 => array (size = 3) 0 => array (size = 3) 'welfarename' => string 'packet Fool' (length = 9) 'welfareid' => string 'URL _ 1' (length = 5) 'xyid' => int 1 1 => array (size = 3) 'welfarename' => string 'first class' (length = 9) 'welfareico '=> string 'URL _ 2' (length = 5) 'xyid' => int 1 2 => array (size = 3) 'welfarename' => string 'chela' (length = 6) 'welfareid' => string 'URL _ 4' (length = 5) 'xyid' => int 1 1 => array (size = 2) 0 => array (size = 3) 'welfarename' => string 'first class' (length = 9) 'welfareico '=> string 'URL _ 2' (length = 5) 'xyid' => int 2 1 => array (size = 3) 'welfarename' => string 'buy buy '(length = 9) 'welfareid' => string 'URL _ 3' (length = 5) 'xyid' => int 2 ----------------------------------------------------- array (size = 3) 0 => array (size = 11) 'xyid' => int 1 'xylocation' => string 'Seoul '(length = 6) 'commentnum' => int 3 'visitornum' => int 1 1 => array (size = 11) 'xyid' => int 2 'xylocation' => string 'Tokyo '(length = 6) 'commentnum' => int 0' visitornum' => int 1 returns array (size = 3) 0 => array (size = 11) 'xyid' => int 1 'xylocation' => string 'Seoul '(length = 6) 'commentnum' => int 3 'visitornum' => int 1 'welfare' => array (size = 3) 0 => array (size = 3) 'welfarename' => string' packet occupancy '(length = 9) 'welfareico' => string 'URL _ 1' (length = 5) 'xyid' => int 1 1 => array (size = 3) 'welfarename' => string 'first class' (length = 9) 'welfareid' => string 'URL _ 2' (length = 5) 'xyid' => int 1 2 => array (size = 3) 'welfarename' => string 'youche' (length = 6) 'welfareico '=> string 'URL _ 4' (length = 5) 'xyid' => int 1 1 => array (size = 11) 'xyid' => int 2 'xylocation' => string 'Tokyo '(length = 6) 'commentnum' => int 0 'visitornum' => int 1 'welfare' => array (size = 2) 0 => array (size = 3) 'welfarename' => string 'first class' (length = 9) 'welfareico '=> string 'URL _ 2' (length = 5) 'xyid' => int 2 1 => array (size = 3) 'welfarename' => string 'buy buy '(length = 9) 'welfareid' => string 'URL _ 3' (length = 5) 'xyid' => int 2


Reply to discussion (solution)

It is equivalent to taking the first array as the value corresponding to a key of the second array. how can I implement the third array?

Please solve this problem ~~~~~~

For ($ I = 0; $ I
  
  

$ Arr1 = array ('welfarename' => 'package Overview', 'welfareico '=> 'URL _ 1', 'xyid' => 1 ), array ('welfarename' => 'first class', 'welfareico '=> 'URL _ 2', 'xyid' => 1 ), array ('welfarename' => 'chela', 'welfareico '=> 'URL _ 4', 'xyid' => 1 )), array ('welfarename' => 'first class', 'welfareico '=> 'URL _ 2', 'xyid' => 2 ), array ('welfarename' => 'buy buy ', 'welfareico' => 'URL _ 3', 'xyid' => 2 ))); $ arr2 = array ('xyid' => 1, 'xylocation' => 'Seoul ', 'commentnum' => 3, 'visitornum' => 1 ,), array ('xyid' => 2, 'xylocation' => 'Tokyo ', 'commentnum' => 0, 'visitornum' => 1 ,)); foreach ($ arr1 as $ k =>$ v) {$ new [$ v [0] ['xyid'] = $ v ;} foreach ($ arr2 as $ k => $ v) {$ arr2 [$ k] ['welfare'] = $ new [$ v ['xyid'];}

$ Arr1 = array ('welfarename' => 'package Overview', 'welfareico '=> 'URL _ 1', 'xyid' => 1 ), array ('welfarename' => 'first class', 'welfareico '=> 'URL _ 2', 'xyid' => 1 ), array ('welfarename' => 'chela', 'welfareico '=> 'URL _ 4', 'xyid' => 1 )), array ('welfarename' => 'first class', 'welfareico '=> 'URL _ 2', 'xyid' => 2 ), array ('welfarename' => 'buy buy ', 'welfareico' => 'URL _ 3', 'xyid' => 2 ))); $ arr2 = array ('xyid' => 1, 'xylocation' => 'Seoul ', 'commentnum' => 3, 'visitornum' => 1 ,), array ('xyid' => 2, 'xylocation' => 'Tokyo ', 'commentnum' => 0, 'visitornum' => 1 ,)); foreach ($ arr1 as $ k =>$ v) {$ new [$ v [0] ['xyid'] = $ v ;} foreach ($ arr2 as $ k => $ v) {$ arr2 [$ k] ['welfare'] = $ new [$ v ['xyid'];}


This solves the problem. I do not have a deep understanding of arrays.

More training, more writing, and more profound

More training, more writing, and more profound


Taught

For ($ I = 0; $ I
     
    


This can also be implemented by the moderator, but there will be a lot more Redundant Arrays. thank you too.

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.