Re: Named pair array from variable
| From: | Ashley Sheridan | Date: | Mon, 29 Jun 2009 22:35:31 +0000 |
| Subject: | Re: Named pair array from variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294723@lists.php.net to get a copy of this message | ||
On Mon, 2009-06-29 at 12:06 -0700, Mikey Knutson wrote:
> Is this even possible? I'm building a string, properly formatted, to create
> a named pair or associative array. The string is fine, and when I use it
> directly to create the array, all is well. When I try to use the var to
> create the array, I get an empty array (I think). Huh?
>
> Here is what I have:
>
> $myString = "'username' => 'password' , 'mickey' =>
> 'mouse' , 'donald' =>
> 'duck'";
> $myArray = array($myString);
> print ("array val: $myArray[username]"); // get an empty string here
>
>
>
>
What you're doing is assigning the string "'username' => 'password'
,
'mickey' => 'mouse' , 'donald' => 'duck'" to the
first index of the
array. What you should be doing is assigning the elements one by one to
the array so that they have proper indexes.
Thanks
Ash
www.ashleysheridan.co.uk