array_push - $arrayName from Form?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 7
Joined: Wed Apr 17, 2013 8:31 am

Wed Apr 17, 2013 9:37 am

ok, im new to this so youll have to forgive me for asking stupid questions.

Im trying to build a simple 'enrollment' form to add names to an array. I have 3 arrays (or classrooms if you like) and i have 2 text inputs to specify 1. name and 2. classroom. I will eventually swap out the textform for a radio button to choose the class.

array_push($arrayName, 'value');

I set the 'name' text box and assigned it to the $name variable.
array_push($arrayname, $name); works just fine.

I cant work out how to take input from my form and convert it into the name of my array. For testing purposes i can type 'classone' (name of array) into the text box to submit it but i cant figure out how to take that string and convert it into a variable i can use in the array_push function. Any help is appreciated, just looking for a point in the right direction!


Code: Select all

			$test = '$'.$class;
			echo "$test";
			array_push($test, $name);
I thought that might work, the string is echo'ed correctly as $classone but im guessing $name is being added to a new $test array. Could be wrong >.< grrrr

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Wed Apr 17, 2013 2:05 pm

If you're using a form, the values of your inputs will appear in your super global variables depending on the method specified in the form. Here's a quick video that should shed some light on it for you: ... et-request

Post Reply