N-Bomb(Nerd) Posted August 11, 2009 Share Posted August 11, 2009 I apologize in advance for the lame topic subject, however I don't exactly know what to call what I need assistance with. I'm trying to find a way to setup an array to handle what I need. I want to have 'profiles' for different things, example below: Name --- Age -- Weight ------------------------ Dan --- 15 --- 100 Jon --- 16 --- 123 Vav --- 12 --- 97 Now from the form I know the name of the information I need to use. Now is it possible to use an array with only the first value (the name) and pull the rest of the information? Example: echo 'Age: ' . $Profile['Dan'][Age]; echo 'Weight: ' . $Profile['Dan'][Age][Weight]; I don't want to use any sort of database.. I just want to keep all of the information within the script. If possible.. how would I construct an array like this? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 11, 2009 Share Posted August 11, 2009 <?php //Cleaner $Profile['Dan'] = array ( "Age"=>"23", "Weight"=>"220", "foo"=>"bar" ); //Shorter $Profile['Fred'] = array ("Age"=>"33","Weight"=>"150","foo"=>"bar"); //Echo his 'Age' and 'Weight' key echo $Profile['Dan']['Age'].'<br/>'; echo $Profile['Dan']['Weight'].'<br/>'; //Example check if ($Profile['Dan']['Age'] > 18) { echo "Dan is older than 18!"; }; ?> To get an array within an array.. $Profile['Fred'] = array ("Age"=>"33","Weight"=>"150","foo"=>array("1"=>"one","2"=>"two")); $Profile['Fred']['foo']['1']; Sorry for all the edits, tiring night. Quote Link to comment Share on other sites More sharing options...
N-Bomb(Nerd) Posted August 11, 2009 Author Share Posted August 11, 2009 Wow, much easier than I expected.. thanks for the example oni-kun. 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.