note 29476 modified in function.explode by aidan

From: Date: Sun, 27 Jun 2004 14:28:26 +0000
Subject: note 29476 modified in function.explode by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71929@lists.php.net to get a copy of this message
Use this function to assign keys to the result array instead of numbered entries. The $keys array must be a numeric array and must have same size entries in the $string. <?php function explodeKeys($separator, $string, $keys) { $res = explode($separator, $string); if (@is_array($res) && @is_array($keys)) { $size = sizeof($res); if ($size == sizeof($keys)) { for ($i=0; $i < $size; $i++) { $res[$keys[$i]] = $res[$i]; unset($res[$i]); } return $res; } } return false; } ?> --was-- Use this function to assign keys to the result array instead of numbered entries. The $keys array must be a numeric array and must have same size entries in the $string. function explodeKeys($separator, $string, $keys) { $res = explode($separator, $string); if (@is_array($res) && @is_array($keys)) { $size = sizeof($res); if ($size == sizeof($keys)) { for ($i=0; $i < $size; $i++) { $res[$keys[$i]] = $res[$i]; unset($res[$i]); } return $res; } } return false; } http://php.net/manual/en/function.explode.php

« previous php.notes (#71929) next »