View Full Version : Please explain this line of code. Thanks
Could someone explain the code below. What I'm trying to do is get $_POST variable where the name, address, city, state and zip code is in the code.
$info=array(1=>array('line1'=>'John Smith', 'line2'=>'1000 First Street', 'line3'=>'PO Box 123', 'line4'=>'Anytown, CA 41000'),
2=>array('line1'=>'Bill Gates', 'line2'=>'456 Money Way', 'line4'=>'Seattle, WA 16456'),
3=>array('line1'=>'Steve Jobs', 'line2'=>'1 Inifinite Loop', 'line4'=>'Cupertino, CA 42389'));
Thanks
Fumigator
04-24-2007, 07:10 PM
It's an array assignment. It's the same thing as doing this:
$info[1]['line1'] = 'John Smith';
$info[1]['line2'] = '1000 First Street';
$info[1]['line3'] = 'PO Box 123';
$info[1]['line4'] = 'Anytown, CA 41000';
$info[2]['line1'] = 'Bill Gates';
$info[2]['line2'] = '456 Money Way';
$info[2]['line4'] = 'Seattle, WA 16456';
$info[3]['line1'] = 'Steve Jobs';
$info[3]['line2'] = '1 Inifinite Loop';
$info[3]['line4'] = 'Cupertino, CA 42389';
rafiki
04-24-2007, 07:10 PM
www.google.com/search?q=php+arrays
www.google.com/search?q=$_POST+variable
http://uk.php.net/variables.predefined
http://uk.php.net/function.array
these will also help
how would I get variables in the place of the name, address etc in the array
I have tried several things but none won't work
Thanks
$info[1]['line1'] = ?;
$info[1]['line2'] = ?;
$info[1]['line3'] = '?';
$info[1]['line4'] = '?';
TheShaner
04-25-2007, 07:12 PM
Please be patient when awaiting an answer. Posting again with an "Anyone?" only a couple hours later will not get you a faster response.
Storing a variable into an array:
$name = 'John Smith'; // Variable $name storing the name John Smith
$info[1]['line1'] = $name; // Store the contents of the $name variable into array
Just an observation of mine, but if you don't know how to use variables, you may want to run through a PHP tutorial before continuing to deal with multidimensional arrays. I mean no disrespect in that comment, but it'll save you lots of time in the future.
-Shane
kbluhm
04-25-2007, 07:40 PM
Please be patient when awaiting an answer.
Agreed. Your question is no more important than anyone else's, and this is not real-time chat. It is still sitting right there in all it's original splendor for anyone to see.
how would I get variables in the place of the name, address etc in the array
This question makes very little sense. Do you mean you'd like the _POST values to populate the arrays? If so, just assign $_POST['XXX'] as an array value rather than hard-coding string values.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.