Home  >  Article  >  Backend Development  >  PHP code to merge element values ​​of multiple arrays without duplication

PHP code to merge element values ​​of multiple arrays without duplication

WBOY
WBOYOriginal
2016-07-25 08:57:44933browse
  1. /**
  2. * Merge element values ​​of multiple arrays without duplication
  3. * by bbs.it-home.org
  4. */
  5. function array_values_merge()
  6. {
  7. $argc = func_num_args();
  8. if ($argc == 0) {
  9. return false;
  10. } else if ($argc == 1) {
  11. $arg1 = func_get_arg(0);
  12. if (is_array($arg1)) {
  13. return array_values(array_unique($arg1));
  14. } else {
  15. return array($arg1);
  16. }
  17. } else {
  18. $arg_list = func_get_args();
  19. $arr = array();
  20. for ($i=0; $i<$argc; $i++) {
  21. $arr = array_merge($arr, $arg_list[$i]);
  22. }
  23. return array_values(array_unique($arr));
  24. }
  25. }
  26. //调用示例
  27. $a = array('huanghao');
  28. $b = array('huanghao','zhaodefang','jiangyu');
  29. $c = array('zhaodefang','hh');
  30. print_r(array_values_merge($a, $b, $c));
复制代码


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