答案 0 :(得分:0)
使用array_slice
:
$input_array = array('a'=>'a', 'b'=>'b', 'c'=>'c', 'd', 'e');
$first_two = array_slice($input_array, 0, 2, true);
答案 1 :(得分:0)
从您的代码中看起来您确实需要密钥和值...
<select name="country">
<?php
foreach($countryArray as $code=>$country){
echo "<option value=".$code.">".$country."</option>";
}
</select
答案 2 :(得分:0)
您可以使用array_slice
$arrays = [
"" => "Select country",
"AF" => "Afghanistan",
"DZ" => "Algerian",
"AO" => "Angola"
];
$first = array_slice($arrays, 0, 1);
$second = array_slice($arrays, 1, 1);
$first_two = array_slice($arrays, 0, 2, true);
$first_three = array_slice($arrays, 0, 3, true);