2014-10-18 136 views
1

我正面臨着這個問題,我似乎無法找到出路。我有這樣一個數組,PHP選擇n個陣列

$array = [(
    "name" => "marks", "score" => 24), 
    ("name" => "arsh", "score"=>54), 
    ("name" => "jack" , "score" =>32), 
    ("name" => "welch" , "score" =>34), 
    ("name" => "sid" , "score" =>32)]; 

如何可以選擇前n個數組,如可以說我需要前2個數組。所以出這個數據的?我怎樣才能像這樣的輸出,

$array = [(
    "name" => "marks", "score" => 24), 
    ("name" => "arsh", "score"=>54)] 

感謝

+2

[array_slice()](HTTP:// WWW。 php.net/manual/en/function.array-slice.php)應該有幫助 – 2014-10-18 14:53:44

+2

['array_slice($ array,0,2)'](http://www.php.net/array_slice)。 – h2ooooooo 2014-10-18 14:53:47

回答