There are two ways to merge arrays in php. Let me explain the specific method slowly:
1. The array_merge() function merges arrays
The specific example is as follows:
<code><span><span><?php</span><span>$a</span> = <span>array</span>( <span>'where'</span> => <span>'uid=1'</span>, <span>'order'</span> => <span>'uid'</span>, <span>'limit'</span> => <span>'5'</span> ); <span>$b</span> = <span>array</span>( <span>'where'</span> => <span>'uid=2'</span>, <span>'order'</span> => <span>'uid desc'</span>, ); <span>$c</span> = array_merge(<span>$a</span>,<span>$b</span>); print_r(<span>$c</span>); <span>$d</span> = array_merge(<span>$b</span>,<span>$a</span>); print_r(<span>$d</span>);</span></span></code>
The output result is as follows:
Pay attention to the where and uid fields, these two fields are the $a and $b arrays Common fields in China, what can be concluded by paying attention to the difference between the values of these two fields in the results?Array ( [where] => uid=2 [order] => uid desc [limit] => 5 )
Array ( [where] => uid=1 [order] => uid [limit] => 5 )
<code><span><span><?php</span><span>$a</span> = <span>array</span>( <span>'where'</span> => <span>'uid=1'</span>, <span>'order'</span> => <span>'uid'</span>, <span>'limit'</span> => <span>'5'</span> ); <span>$b</span> = <span>array</span>( <span>'where'</span> => <span>'uid=2'</span>, <span>'order'</span> => <span>'uid desc'</span>, ); <span>$c</span> = <span>$a</span>+<span>$b</span>; print_r(<span>$c</span>); <span>$d</span> = <span>$b</span>+<span>$a</span>; print_r(<span>$d</span>);</span></span></code>
The output result is as follows:
As above, we still pay attention to the values of the where and order fields. What conclusions can we draw?Array ( [where] => uid=1 [order] => uid [limit] => 5 )
Array ( [where] => uid=2 [order] => uid desc [limit] => 5 )
The above introduces the method of merging arrays in PHP, including the methods of PHP. I hope it will be helpful to friends who are interested in PHP tutorials.