note 106729 deleted from function.array by tularis
| From: | tularis@php.net | Date: | Fri, 02 Dec 2011 11:38:56 +0000 |
| Subject: | note 106729 deleted from function.array by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184853@lists.php.net to get a copy of this message | ||
Note Submitter: facebook / The.DJ.Cornbread
Reason: useless
----
I have seen many questions about this so I chose to comprise a simple show of how to use
multi-dimensional arrays that include variables. (your welcome)
This script uses a variables in making and calling info from an array.
<?php
$like = "i like ";
$love = "i love ";
$passcode = "abc";
$users_selection = "abcsecretlife"; // selection from a form or something...
$options = array( // first dimension
"apples" => array( //second dimension
"red" => array( //third dimension
"0" => "im allergic to em",
"red" => $like."that they are red.",
"fried"=> $love."that they can be fried."
),
"green" => array(
"0" => "im allergic",
"green" => $like."that they are green",
"default"=> $love."the fact their sour."
)
),
"oranges yum" => array(
"ripe" => array(
"0" => "ouch my eye",
"sweet" => $like."that their sweet",
"yum"=> "yummmmmmy"
),
"rotten" => array(
"argh" => "son of a...",
"custom" => $like."nothing about em",
"smell"=> "ooh, ooh, that smell"
)
),
"DJ_Cornbread" => array(
"music" => array(
"0" => "hurts my ears",
"music" => $love."his stuff",
"huh"=> $like."...wait...what is electronica?"
),
$passcode."secretlife" => array(
"0" => "i accidently",
"wha" => $like."really?!?",
"bandcamp"=> $love."that one time at bandcamp."
)
)
);
echo $options['DJ_Cornbread'][$users_selection]['bandcamp'];
?>
output
i love that one time at bandcamp