Log in

View Full Version : How can I set parts of this array to variables?



brainbuzzmedia
10-28-2011, 06:48 AM
I have an array within an array that contains settings. I need to figure out how to target specific parts of the array so i can turn them into a variable or output them. Here is the array's vardump:

array(2) { [0]=> object(stdClass)#101 (1) { ["type"]=> string(9) "wordpress" } [1]=> object(stdClass)#122 (6) { ["type"]=> string(7) "divider" ["width"]=> string(4) "full" ["divider_type"]=> string(5) "solid" ["color"]=> string(0) "" ["padding_top"]=> string(0) "" ["padding_bottom"]=> string(0) "" } }

I really don't know php that well.

djr33
10-28-2011, 07:00 AM
$array['key']['anotherkey']

The basic format is $array['key'], but if you have layers then you can just add it to the end.

Or, look at it like this:
$temp = $array['key'];
$temp['anotherkey'];

(There are two words for the name that refers to the subpart of the array, either a "key" or an "index". Usually a "key" refers to when you are looping through the array to find specific entries, and an index refers to when you name it that, but they actually mean the same thing, effectively.)