JPark Posted August 13, 2009 Share Posted August 13, 2009 I am trying to display the contents of an array and having a problem. I am getting an array of states (and state abbreviations) from a form and throwing this into a SESSION array ($_SESSION['states'] = $_POST['states'] Later, I want to echo these choices back, without the state abbreviations. Let's say the customer gives me Maryland-MD, Virginia-VA and Delaware-DE. If I use foreach($_SESSION['states'] as $key=>$value) { $stateName = explode("-",$_SESSION['states']); echo $stateName[0].' <br />'; } echo "</blockquote>"; . I get Notice: Array to string conversion in /vs/webdev/docs/econ/notifyme/state_entry.php on line 469 Array Notice: Array to string conversion in /vs/webdev/docs/econ/notifyme/state_entry.php on line 469 Array What am I doing wrong? What should I do? Thanks, Joe Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted August 13, 2009 Share Posted August 13, 2009 when you use a foreach loop, you refer to each entry in the variable as the value variable you use. so instead of using $_SESSION['states'] in your code, you have to use $value. so: foreach($_SESSION['states'] as $key=>$value) { $stateName = explode("-",$value); echo $stateName[0].' <br />'; } echo "</blockquote>"; should work for what you're doing Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.