Keith
Keith

Reputation: 26499

How to access the subarray data of a multidimensional array?

Here's a quickie for the pros:

How do I display Value 1, 2, 3 etc as it's in it's third array?

$meta_boxes = array

  (
        "checkbox" => array
        (
              "name" => "checkbox",
              "title" => "",
              "description" => "This is an example of a checkbox field.",
              "type" => "checkbox",
              "rows" => "",
              "width" => "",
              "options" => array
              (
                    "1" => "Value 1",
                    "2" => "Value 2",
                    "3" => "Value 3"
              )
  ),

Upvotes: 0

Views: 396

Answers (2)

Jacob Relkin
Jacob Relkin

Reputation: 163288

$str = '';
foreach($meta_boxes['checkbox']['options'] as $k => $v) {
   $str .= $v . "\n";
}

Upvotes: 3

Michael Madsen
Michael Madsen

Reputation: 55009

$meta_boxes['checkbox']['options']['1'] will give you the string "Value 1" from the array, and then you can do whatever you want with that value.

You should now be able to figure out how to access the other two.

Upvotes: 2

Related Questions