homepage Welcome to WebmasterWorld Guest from 54.204.59.230
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Parse out associative array
JohnKelly




msg:4312437
 5:26 pm on May 14, 2011 (gmt 0)

Try as I might, I cannot parse out this array. I have an array, when I run var_dump($array->chart()); it outputs the following


array(5) { ["i1"]=> string(3) "430" ["c1"]=> string(2) "21" ["ct2"]=> string(5) "98%" ["ec3"]=> string(6) "68.4" ["ea4"]=> string(5) "3.9" }



I would like to get something like:

i1 = 430
c1 = 21
ct2 = 98%
ec3 = 68.4
ea4 = 3.9

... but I cannot parse out the array, for some reason I always find associative arrays difficult.

Can anyone please help?

 

agent_x




msg:4312477
 7:39 pm on May 14, 2011 (gmt 0)

Is it not simply extract($array) ?

agent_x




msg:4312479
 7:44 pm on May 14, 2011 (gmt 0)

Or am I not understanding what you were trying to do? If it's just to echo out the contents of the array it's something like

foreach($array as $key=>$value)
{
echo $key . " = " . $value . "<br>";
}

JohnKelly




msg:4312603
 5:26 am on May 15, 2011 (gmt 0)

Thanks agent_x for the tip on extract($array)!

Here is what I used:

extract($array->chart(), EXTR_PREFIX_SAME, "wddx");
echo "$i1, $c1, $ct2, $ec3, $ea4";

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved