h3110w0r1d Posted February 5, 2011 Share Posted February 5, 2011 I guess I'll rephrase since my wording wasn't very clear. Why don't echo "<p>\n"; if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { if ($field == "City") { echo $field . ' : ' . $val . "<br />\n"; $val = $cityvar; } if ($field == "ZipPostalCode") { echo $field . ' : ' . $val . "<br />\n"; $val = $zipvar; } if ($field == "CountryName") { echo $field . ' : ' . $val . "<br />\n"; $val = $countryvar; } } } echo "</p>\n"; Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/ Share on other sites More sharing options...
h3110w0r1d Posted February 5, 2011 Author Share Posted February 5, 2011 ... Why don't $cityvar, $zipvar, and $countryvar have values? Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170389 Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 because you don't set them to anything? Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170390 Share on other sites More sharing options...
h3110w0r1d Posted February 5, 2011 Author Share Posted February 5, 2011 How would that be done? I updated my original post to show what I've tried and doesn't work. Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170392 Share on other sites More sharing options...
sunfighter Posted February 5, 2011 Share Posted February 5, 2011 First get rid of those \n why are they in a php/html file Next I have never heard of 'is_array ' that probibly your error maybe in_array Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170394 Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 to assign a value to a variable, put the variable on the left and the value you are trying to assign to it on the right. in the middle, there should be an equal sign. $cityvar = $val; Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170395 Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 First get rid of those \n why are they in a php/html file Next I have never heard of 'is_array ' that probibly your error maybe in_array \n is a line break. nothing wrong there. is_array is a function: http://php.net/manual/en/function.is-array.php Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170396 Share on other sites More sharing options...
h3110w0r1d Posted February 5, 2011 Author Share Posted February 5, 2011 to assign a value to a variable, put the variable on the left and the value you are trying to assign to it on the right. in the middle, there should be an equal sign. $cityvar = $val; This. Thank you, maybe had a little too much to drink last night. Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170399 Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Or maybe not enough. Link to comment https://forums.phpfreaks.com/topic/226820-foreach-loop-variables/#findComment-1170409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.