How to merge different array elements in php

藏色散人
Release: 2023-03-13 18:18:01
Original
2379 people have browsed it

php method to merge different array elements: 1. Create a PHP sample file; 2. Use "array_keys(array_flip($a) array_flip($b) array_flip($c));" to multiple Just merge the arrays to remove duplicates.

How to merge different array elements in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

How does php merge different array elements?

Multiple array deduplication

array_keys(array_flip($arr1)+array_flip($arr2))
Copy after login

array_keys() function returns a new array containing all the key names in the array.

If the second parameter is provided, only the key name with the key value is returned.

Return a new array containing all the key names in the array:

<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a));
?>
Copy after login

Running results:

Array ( [a] => red [b] => green )
Array ( [0] => Volvo [1] => BMW [2] => Toyota )
Copy after login

Techniques for merging and deduplicating multiple arrays

$a = array(&#39;1001&#39;,&#39;1002&#39;);
$b = array(&#39;1002&#39;,&#39;1003&#39;,&#39;1004&#39;);
$c = array(&#39;1003&#39;,&#39;1004&#39;,&#39;1005&#39;);
$d = array_keys(array_flip($a) + array_flip($b) + array_flip($c));
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to merge different array elements in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template