2011-11-23 48 views
0

顯示1個陣列的含量如果具有和陣列是這樣的:只有它的名字

Array ( 
[Example1] => Array 
    ( 
     [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => 
    ) 
[Example2] => Array 
    ( 
     [0] => [1] => [2] => [3] => [4] => 
     [5] => [6] => [7] => [8] => [9] => 
     [10] => [11] => [12] => [13] => [14] => 
     [15] => [16] => [17] => [18] => [19] => 
     [20] => [21] => [22] => [23] => [24] => 
     [25] => [26] => [27] => [28] => [29] => 
     [30] => [31] => [32] => [33] => [34] => 
     [35] => [36] => [37] => [38] => [39] => 
     [40] => [41] => [42] => [43] => [44] => 
     [45] => [46] => [47] => [48] => [49] => 
     [50] => [51] => [52] => [53] => [54] => 
     [55] => [56] => [57] => [58] => [59] => 
     [60] => [61] => [62] => [63] => [64] => 
     [65] => [66] => [67] => [68] => [69] => 
     [70] => [71] => [72] => [73] => [74] => 
     [75] => [76] => [77] => [78] => [79] => 
     [80] => [81] => [82] => [83] => [84] => 
     [85] => [86] => [87] => [88] => [89] => 
     [90] => [91] => [92] => [93] => [94] => 
     [95] => [96] => [97] => [98] => [99] => 
     [100] => [101] => [102] => [103] => [104] => 
     [105] => [106] => [107] => [108] => [109] => 
     [110] => [111] => [112] => [113] => [114] => 
     [115] => [116] => [117] => [118] => [119] => 
     [120] => [121] => [122] => [123] => [124] => 
     [125] => [126] => [127] => [128] => [129] => 
     [130] => [131] => [132] => [133] => [134] => 
    ) 
) 

有是2門​​主陣列(例1例2 &)和那些另一個陣列而成。我想知道我怎麼只能叫像「例題」只有1陣列,因此只打印一個而忽略「示例1」

請注意,有可能是2個以上主陣列。

如果與陣列我想建立一個下拉菜單是什麼,在這裏我有什麼:

$__selectGroups = ''; 
    foreach ($groups as $key => $options) 
    { 
     sort($options); 
     if ($key !== '') 
     { 
      $__selectGroups .= '<optgroup label="'.$key.'">'; 
     } 
     $__selectGroups .= implode("\n", $options); 
     if ($key !== '') 
     { 
      $__selectGroups .= '</optgroup>'; 
     } 
    } 

我怎麼能告訴建立下拉只有例題,而忽略其他人呢?

+0

也許你可以'的print_r()'這所以它是更具可讀性和無法在同一行?謝謝。 – DeaconDesperado

+0

'的print_r($陣列[ '例2'])'? –

+0

有點混淆的問題。 – 2011-11-23 15:07:12

回答

6

我不知道我理解的問題...似乎太簡單了:

print_r($yourArray['Example1']); 

既然你編輯你的問題,我認爲要做到這一點?

foreach ($yourArray['Example1'] as $key => $value) { 
} 

這一模式訪問嵌套數組適用全線...

0

你需要的東西是這樣的:

echo '<pre>'; 
print_r($yourArray['Example1']); 
print_r($yourArray['Example2']); 
echo '<pre>'; 

,或者您需要更多的東西闡述?

相關問題