Advanced Search

Results 1 to 2 of 2

Thread: How can I set parts of this array to variables?

  1. #1
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How can I set parts of this array to variables?

    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.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    $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.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •