可能重複:
How to extract data out of a specific PHP array如何讀取數組中的數據?
我有我試圖來從特定鍵中的所有元素的數組的關鍵是shard3
。 結果應該是'user'=>'root','password'=>'3', 'db'=>'test', 'port'=>3307
private $shard_list = array (
'shard1' => array('host'=>'127.0.0.1',
'user'=>'root',
'password'=>'1',
'db'=>'test',
'port'=>3306
),
'shard2' => array('host'=>'127.0.0.2',
'user'=>'root',
'password'=>'2',
'db'=>'test',
'port'=>3307
),
'shard3' => array('host'=>'127.0.0.3',
'user'=>'root',
'password'=>'3',
'db'=>'test',
'port'=>3307
),
'shard4' => array('host'=>'127.0.0.4',
'user'=>'root',
'password'=>'4',
'db'=>'test',
'port'=>3307
)
我想讀的所有元素shard3
。讀取所有元素的方式是什麼?
詢問之前請閱讀[PHP手冊](http://www.php.net/manual/en/langref.php)。 – Jocelyn 2012-08-02 23:34:33
並閱讀您的權利... – 2012-08-02 23:34:51
$ data = $ shard_list ['shard3']; – mrok 2012-08-02 23:34:53