Re: function for string to array (map)?
| From: | Aidan Lister | Date: | Fri, 18 Jun 2004 08:40:50 +0000 |
| Subject: | Re: function for string to array (map)? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188535@lists.php.net to get a copy of this message | ||
No, because that's not a standard format.
You'll have to write your own function (as you've done).
If you're looking to store an array as a string, look at serialize()
"Pete Forman" <pete.forman@westerngeco.com> wrote in message
news:oenii283.fsf@wgmail2.gatwick.eur.slb.com...
> 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
> pete.forman@westerngeco.com -./\.- opinion of Schlumberger, Baker
> http://petef.port5.com -./\.- Hughes or their
> divisions.