Home >Backend Development >PHP Tutorial >Detailed explanation of how to find different elements in two arrays in PHP

Detailed explanation of how to find different elements in two arrays in PHP

*文
*文Original
2018-01-05 17:54:562366browse

How to find different elements in two arrays in PHP? This article mainly introduces the method of querying different elements in two arrays in PHP, involving related techniques of PHP array difference operation and array merging. Friends in need can refer to it. I hope to be helpful.

<?php
  $a = array(
  "max_allow_dialogs",
  "livechat_server_ip",
  "livechat_service_time",
  "abort_zh_cn",
  "abort_zh_tw",
  "abort_en_usa",
  "welcome_zh_cn",
  "welcome_zh_tw",
  "welcome_en_usa",
  "timeout_zh_cn",
  "timeout_zh_tw",
  "timeout_en_usa",
  "absence_zh_cn",
  "absence_zh_tw",
  "absence_en_usa"
  );
  $b = array(
  "max_allow_dialogs",
  "livechat_server_ip",
  "livechat_service_time",
  "abort_zh_cn",
  "abort_zh_tw",
  "abort_en_usa",
  "welcome_zh_cn",
  "welcome_zh_tw",
  "welcome_en_usa",
  "timeout_zh_cn",
  "timeout_zh_tw",
  "timeout_en_usa",
  );
  $c = array_merge(array_diff($a,$b),array_diff($b,$a));
  print_r($c);
?>

Result:

Array
(
  [0] => absence_zh_cn
  [1] => absence_zh_tw
  [2] => absence_en_usa
)

Related recommendations:

Summary of PHP array sorting method

PHP Method of converting between arrays and strings

php array function current() definition and usage

The above is the detailed content of Detailed explanation of how to find different elements in two arrays in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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