Jump to content

[SOLVED] Need Some Help


N-Bomb(Nerd)

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/169730-solved-need-some-help/
Share on other sites

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.