note 106729 added to function.array
| From: | facebook/The dot DJ dot Cornbread at osu1 dot php dot net | Date: | Fri, 02 Dec 2011 06:20:58 +0000 |
| Subject: | note 106729 added to function.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184847@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 98.70.184.173
----
Manual Page -- http://www.php.net/manual/en/function.array.php
Edit -- https://master.php.net/note/edit/106729
Del: integrated -- https://master.php.net/note/delete/106729/integrated
Del: useless -- https://master.php.net/note/delete/106729/useless
Del: bad code -- https://master.php.net/note/delete/106729/bad+code
Del: spam -- https://master.php.net/note/delete/106729/spam
Del: non-english -- https://master.php.net/note/delete/106729/non-english
Del: in docs -- https://master.php.net/note/delete/106729/in+docs
Del: other reasons-- https://master.php.net/note/delete/106729
Reject -- https://master.php.net/note/reject/106729
Search -- https://master.php.net/manage/user-notes.php