note 105822 modified in function.array-combine by danbrown
| From: | danbrown@php.net | Date: | Sun, 18 Sep 2011 15:48:15 +0000 |
| Subject: | note 105822 modified in function.array-combine by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183259@lists.php.net to get a copy of this message | ||
I needed a function that truncated extra values, and only went as far as keys without throwing a
warning as array_combine does.
<?php
function safeArrayCombine($keys, $values) {
$combinedArray = array();
for ($i=0, $keyCount = count($keys); $i < $keyCount; $i++) {
$combinedArray[$keys[$i]] = $values[$i];
}
return $combinedArray;
}
?>
--was--
I needed a function that truncated extra values, and only went as far as keys without throwing a
warning as array_combine does.
function safeArrayCombine($keys, $values) {
$combinedArray = array();
for ($i=0, $keyCount = count($keys); $i < $keyCount; $i++) {
$combinedArray[$keys[$i]] = $values[$i];
}
return $combinedArray;
}
http://php.net/manual/en/function.array-combine.php