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
Placing string variables within array fucntion
Moderator: General Moderators
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: Placing string variables within array fucntion
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.