note 11281 added to Array Functions
| From: | nospamjong at jong dot org | Date: | Wed, 14 Feb 2001 08:29:00 +0000 |
| Subject: | note 11281 added to Array Functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11036@lists.php.net to get a copy of this message | ||
It occurred to me that there doesn't seem to be a good way to convert a normal indexed list to
an associative array. So here's a quick-n-dirty way if you're in a bind:
$array = ('key1','val1','key2','val2',...);
$s = 0;
$st = '';
$new_array = '';
foreach ($array as $v) {
if ($s == 0) {
$new_array["$v"] = $v;
$st = $v;
$s++;
} else {
$new_array["$st"] = $v;
$s = 0;
}
}
http://www.php.net/manual/en/ref.array.php