php - setting input in an associate array then loop through the entries -
i have associative array that's being populated user input. set array session variable can add on top of array every time new input entered.
warning: invalid argument supplied foreach()
<?php session_start(); ?> <h1> <?php foreach ($_session['formonearrayglobal'] $x => $xvalue) { echo $x . $xvalue; } ?> </h1> <form action="send.php" method="post" name="form-one"> <input type="text" name="name"> <input type="text" name="number"> <button type="submit">submit</button> </form> <?php session_start(); try { if (!empty($_post['form-one'])) { $variableone = $_post['name']; $variabletwo = $_post['number']; $formonearray[$variableone] = $variabletwo; $_session['formonearrayglobal'] = $formonearray; } catch(exception $e) { echo $e; } ?>
you have put check first time if there no data in $_session['formonearrayglobal']
if(isset($_session['formonearrayglobal']) && !empty($_session['formonearrayglobal'])){ foreach ($_session['formonearrayglobal'] $x => $xvalue) { echo $x . $xvalue; } }
Comments
Post a Comment