note 106616 modified in function.array-merge by danbrown

From: Date: Tue, 29 Nov 2011 15:55:45 +0000
Subject: note 106616 modified in function.array-merge by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184801@lists.php.net to get a copy of this message
Uniques values merge for array_merge function: <?php function array_unique_merge() { $variables = '$_'.implode(',$_',array_keys(func_get_args())); $func = create_function('$tab', ' list('.$variables.') = $tab; return array_unique(array_merge('.$variables.'));'); return $func(func_get_args()); } ?> Doesn't work on objects. Smarter way for uniques values merge array: <?php function array_unique_merge() { return array_unique(call_user_func_array('array_merge', func_get_args())); } ?> Example 1: $a = array(1,2); $b = array(2,3,4); array_unique_merge($a,$b); Return: array(1,2,3,4); Example 2: $a = array(1,2); $b = array(2,3,4); $c = array(2,3,4,5); array_unique_merge($a,$b); Return: array(1,2,3,4,5); Doesn't work on objects. --was-- Uniques values merge for array_merge function: <?php function array_unique_merge() { $variables = '$_'.implode(',$_',array_keys(func_get_args())); $func = create_function('$tab', ' list('.$variables.') = $tab; return array_unique(array_merge('.$variables.'));'); return $func(func_get_args()); } ?> Doesn't work on objects. http://php.net/manual/en/function.array-merge.php

« previous php.notes (#184801) next »