Php calculates the special intersection of these two arrays. it seems simple. In fact, $ x = array (& nbsp; array (& quot; a & quot;, 2), & nbsp; array (& quot; B & quot;, 4), & nbsp; array (& quot; e & quot;, 3); $ y = array (& quot; B & quot;, & quot; php calculates the special intersection of the two arrays, which seems simple but not actually
$ X = array (
Array ("a", 2 ),
Array ("B", 4 ),
Array ("e", 3)
);
$ Y = array ("B", "f ");
The following result is required:
Array (
Array ("B", 4 ),
Array ("f", 0)
)
The next thought is to generate a new array based on $ y. because $ y has two elements, the new array also has two elements. because $ x has B, therefore, B takes the value of $ x, that is, 4. because $ x does not contain f, f takes 0.
How does PHP get such a result? Grateful!
------ Solution --------------------
PHP code
Foreach ($ x as $ v) $ tmp [$ v [0] = $ v [1]; foreach ($ y as $ B) $ ar [] = array ($ B, $ tmp [$ B]? $ Tmp [$ B]: 0); print_r ($ ar );