note 76933 deleted from function.array-combine by bjori

From: Date: Thu, 21 Feb 2008 20:28:31 +0000
Subject: note 76933 deleted from function.array-combine by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-136374@lists.php.net to get a copy of this message
Note Submitter: royanee at yahoo dot com ---- This correctly accounts for the error conditions, and actually works. The previous note appears to set all the values in the result array to the value of the last item in the values input array. <?php function array_combine( $keys, $values ) { if( !is_array($keys) || !is_array($values) || empty($keys) || empty($values) || count($keys) != count($values) ) { trigger_error( "array_combine() expects parameters 1 and 2 to be non-empty arrays with an equal number of elements", E_USER_WARNING ); return false; } $keys = array_values($keys); $values = array_values($values); $result = array(); foreach( $keys as $index => $key ) { $result[$key] = $values[$index]; } return $result; } ?>

« previous php.notes (#136374) next »