I am trying to get a simple array from a string.
Ej. [position] => ???? [ heading] => ??? [ pitch] => ??? [ zoom] => ???
But for some reason I get the following error:
Notice: Undefined index: heading on line 21
Here is the PHP code:
<?php
$mysql_data=
"position: 34.032616, -118.286564|
heading: -159.50240187408838|
pitch: 0|
zoom: 2";
$pov = explode("|", $mysql_data);
foreach($pov as $key)
{
$element = explode(": ", $key);
$pov[ $element[0] ] = $element[1];
}
unset($element);
//Testing echoes
print_r($pov);
echo "\n";
echo $pov['heading'];
?>
Also, is there a simpler way to do this in a single go and skip foreach all together?
BTW: I do not need key's 0,1..etc, only labeled ones like 'heading','zoom',etc
parse_str()
:) – Jack Jun 4 '12 at 6:11