morrism35 Posted November 4, 2015 Share Posted November 4, 2015 I know in java this was almost trivial to do. 1. Use a for loop for how many values you want to populate the array with. 2. Enter your user data and assign it to the array. This does not seem so easy in php. This is kind of what i've been working on but it just endlessly keeps asking me for the user endput even though i'm able to output the values, but I want this to be an area that i can sort etc. for($count=0; $count<=3; ++$count){ if($_POST['submit']){ $Signs=$_POST['sign']; ?> <form action='AlphabetizeSigns.php' method='POST' enctype='multipart/form-data'> Type in a zodiac sign<input type='text' name='sign'> <input type='submit' name='submit' value='submit'> Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 4, 2015 Share Posted November 4, 2015 (edited) Not really sure what your doing but this will put the form data into an array. If you are wanting to save the array and keep adding to it you would need to put the data in a session. <?php if($_POST){ $signs[]=$_POST['sign']; echo "<pre>"; print_r($signs); echo "</pre>"; } ?> <form method='post'> Type in a zodiac sign<input type='text' name='sign'> <input type='submit' name='submit' value='submit'> </form> Edited November 4, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
morrism35 Posted November 4, 2015 Author Share Posted November 4, 2015 What I'm trying to do is have the user input 12 names in any order and sort those names in alphabetical order. Php just seems like it doesn't populate an array like other languages like java or c++. Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 4, 2015 Share Posted November 4, 2015 (edited) Here ya go. This is not accounting for 12 names. You would just need to count the elements in the array before adding a new one. <?phpsession_start();if ($_POST) { $_SESSION['signs'][] = $_POST['sign']; }if (isset($_SESSION['signs'])) { echo "Number of Elements: " . count($_SESSION['signs']); sort($_SESSION['signs']); echo "<pre>"; print_r($_SESSION['signs']); echo "</pre>"; }?><form method='post'>Type in a zodiac sign<input type='text' name='sign'><input type='submit' name='submit' value='submit'></form> Edited November 4, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
morrism35 Posted November 4, 2015 Author Share Posted November 4, 2015 Thanks you didn't have to do that. I appreciate it but really trying to learn and understand this. i'm going to look up what autoglobal $_session means. 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.