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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.