Welcome to WebmasterWorld Guest from 54.162.240.235

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Parse out associative array

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

10+ Year Member



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?
7:39 pm on May 14, 2011 (gmt 0)



Is it not simply extract($array) ?
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>";
}
5:26 am on May 15, 2011 (gmt 0)

10+ Year Member



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";
 

Featured Threads

Hot Threads This Week

Hot Threads This Month