Extract specific information from a PHP Multidimensional Array


Posted on 16th Feb 2014 07:03 pm by admin

Howdy! I've racked my brain over this for 24 hours now. I think it's time I asked for help. I'm learning PHP and believe my I've manipulated many code blocks trying to get this to work with for and foreach and while statements. There must be something I'm missing in my studies about arrays but anyway here is the issue.
I have a multidimensional array. From that array I would like to extract only the values of a specific key['name'] so that I can then output it into html form with a special identifier. I was able to do this with nested if statements but that seemed a bit overkill to me.
Here is the code I came up. I know there has to be a more efficient way of getting these results.
Here is the Array code:
Did you know?Explore Trending and Topic pages for more stories like this.
Code: $options = array(

array( "name" => "General Administrative Settings",
"type" => "title"),

array( "type" => "open"),

array( "name" => "Colour Scheme",
"desc" => "Which colour scheme would you like?",
"id" => $shortname."_colourscheme",
"type" => "select",
"std" => "Choose a colour scheme:",
"options" => $styles),

array( "name" => "Portfolio Category",
"desc" => "Select the category portfolio items are being posted in.",
"id" => $shortname. "_portfolio_cat",
"type" => "select",
"std" => "Choose a category:",
"options" => $getcat),

array( "name" => "Definition List",
"desc" => "Select the page used as a definition list page.",
"id" => $shortname."_definition_list",
"type" => "select",
"std" => "Select a page:",
"options" => $getpag),


array( "name" => "Blog page",
"desc" => "Select the page to be used as a blog (post) page.",
"id" => $shortname."_blogpage",
"type" => "select",
"std" => "Select a page:",
"options" => $getpag),

array( "type" => "close")

);
Here is my output code:
Code: <?php
if($options['name'] = "Colour Scheme"){
echo '<div id="col_schm">Colour Scheme</div>';
if($options['name'] = "Definition List") {
echo '<div id="def_lst">Definition List</div>';
}
}
?>

If you can help I would appreciate it.

Thanks
No comments posted yet

Your Answer:

Login to answer
268 Like 48 Dislike
Previous forums Next forums
Other forums

Accept only alpha characters
I've got this bit of code ready for accepting a phrase:

Code: if (!eregi ("", $_POS

PHP arrays into arrays need help
Hello
I am trying to highlight the days on my calendar based on the dates that i have in my datab

LSB (PHP 5.3) problem with static value!
hello,

i'm having a problem. static::$text variable gets lost at some point. can someone plea

preg_match logical error
Code: <?php
$s = file_get_contents("page.html");
preg_match('/<div cla

Baffled by Undefined Index in Simple Array: Please Help!
Hello. I have a form which posts an array to this script. However, I can't seem to access the values

Protecting forms
Alright, I want to protect some forms of mine from SQL Injections, because I had someone earlier spa

Reading Most Recent CSV File in Directory
I thought I had wrapped this project up, but found out that the program I use to FTP a csv file to m

Getting the full city list from maxminds geoip database
I am suprised I can't find any references to this.

I have maxminds geoip lite installed and i

Ajax Issues - Update Panel / Timer. Intellisense doesn't know about them
Type 'System.Web.UI.ScriptManager' does not have a public property named 'UpdatePanel'. That is wha

gmmktime or mktime
I live in the UK, i am within the GMT (with daylight saving time ie 1 hour difrence between summer a

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash