note 36757 modified in function.array-combine by kennyt

From: Date: Mon, 05 Jan 2004 02:49:54 +0000
Subject: note 36757 modified in function.array-combine by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62930@lists.php.net to get a copy of this message
[Ed.: Fixing to above specs.] If you want to use array_combine in PHP4 or so (as this seems to be only working in PHP5) try using the following function: <?php if (!function_exists('array_combine')) { function &array_combine ( $keys, $values ) { if ( count($keys) != count($values) ) return false; $keys = array_values($keys); $values = array_values($values); $newarray = array(); foreach( $keys as $index => $key ) $newarray[$key] = $values[$index]; return $newarray; } } // Call this function like: $array = &array_combine( $keys, $values ); // And check if it ain't false (insert your own errorhandling ofc). ?> --was-- If you want to use array_combine in PHP4 or so (as this seems to be only working in PHP5) try using the following function: function &array_combine ( $keys, $values ) { if ( count($keys) != count($values) ) return null; $keys = array_values($keys); $values = array_values($values); foreach( $keys as $index => $key ) $newarray[$key] = $values[$index]; return $newarray; } // Call this function like: $array = &array_combine( $keys, $values ); // And check if it ain't null (insert your own errorhandling ofc). http://www.php.net/manual/en/function.array-combine.php

« previous php.notes (#62930) next »