----- Original Message ----- 
From: "Pete Forman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 17, 2004 7:22 PM
Subject: [PHP] function for string to array (map)?


> Is there a standard function that converts a string to an array with
> proper keys, not auto generated integers?  I've found myself calling
> explode() twice.  split(), etc. do not seem to offer any improvement.
> 
> $str = "a:x,b:y,c:z";
> $arr = explode(",", $str);
> foreach ($arr as $item) {
>   list($key, $value) = explode(":", $item);
>   $map[$key] = $value;
> }
> 
> Is there a foo() that would do something like this?
> 
> $map = foo(",", ":", $str);
> 
> -- 
> Pete Forman                -./\.-  Disclaimer: This post is originated
> WesternGeco                  -./\.-   by myself and does not represent
> [EMAIL PROTECTED]    -./\.-   opinion of Schlumberger, Baker
> http://petef.port5.com           -./\.-   Hughes or their divisions.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

You just defined your foo function ;-)

Regards, 
Marius

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to