Page 1 of 1

Placing string variables within array fucntion

Posted: Mon May 10, 2010 5:05 pm
by jcf378
Hi - i think there is probably something simple I'm overlooking...
I need to create the following line of php to work within the confines of a more complex project where I have little flexibility about this particular line:

$item = array("sample1"=>"100", "sample2"=>"200", "sample3"=>"300");

Instead of having the text of this array function 'hard-coded', I am trying to fill this array function with a dynamic string variable which I've CURL'd from another page; the result of my CURL is a perfectly-formatted text-string that would fit verbatim into my required array function format:

$resultcurl = ' "sample1"=>"100", "sample2"=>"200", "sample3"=>"300" ' ;

and so i'm trying to get a final working code to look something like:

$item = array($resultcurl);

However, the array function doesn't simply substitute $resultcurl with its associated formatted textstring...
So long story short, is there a way to get the array() function to read and process the textstring as represented by my $resultcurl variable?

many thanks,
-jason fisher

Re: Placing string variables within array fucntion

Posted: Mon May 10, 2010 5:21 pm
by cpetercarter
You could explode() the string on the commas, and then explode() each bit on => to give you the keys and values to put into the array. But it might be simpler to find a way of sending the data in your cURL as an array to start with.