为什么我不能读这个数组? [关闭]

I am currently working on a plugin for WordPress, and i am trying to fetch the widget options using get_options. As a result, I get an array with the options and option name as the key, but for some reason I can't read it:

$options = get_option('widget_widgetname');
var_dump($options);

This is the output of var_dump():

array(2) { [2]=> array(5) 
           { 
             ["string"]=> string(6) "Search" 
             ["title"]=> string(12) "WDSearchForm" 
             ["show_wrapper"]=> string(0) "" 
             ["animate"]=> string(0) "" 
             ["animateWidth"]=> string(2) "80" 
           } 
           ["_multiwidget"]=> int(1) }

but when I do the following, it doesn't work:

echo $options["string"]; // No output
echo $options["title"]; // No output

Looks like this is a nested array. Try:

echo $options[2]["string"];
echo $options[2]["title"];

Here's a reformatted dump that makes the structure a bit clearer:

array(2) {
    [2]=> array(5) { 
             ["string"]=> string(6) "Search" 
             ["title"]=> string(12) "WDSearchForm" 
             ["show_wrapper"]=> string(0) "" 
             ["animate"]=> string(0) "" 
             ["animateWidth"]=> string(2) "80" 
           }
    ["_multiwidget"]=> int(1)
}

This is a multidimentional array. Try echo $options[2]["string"]

echo $options[2]["string"]; // output
echo $options[2]["title"]; // output

It is a two-dimensional array. This should do the trick:

echo $options[2]["string"];
echo $options[2]["title"]; 

or

$options = $options[2];

echo $options["string"];
echo $options["title"]; 

As you can see in your var_dump, you have a multi-dimensional array.

You should use:

echo $options[2]["string"];