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.