0
$example = array('First','Second','Third','Fourth','Fifth',...

以下のコードは、 の 3 番目の要素の設定を解除し$exampleます。

unset($example[2]);

unset3 番目の要素以降のすべての要素を取得するにはどうすればよいですか?

$exampleの値を後でこれにしたい:

$example = array('First','Second','Third');
4

3 に答える 3

2

unset を使用しないで、array_spliceを使用してください:

$example = array('First','Second','Third','Fourth','Fifth');
array_splice($example,3);
//$example = array('First','Second','Third');
于 2012-09-08T02:56:13.167 に答える
1

これに使えますarray_splice

$example = array('First','Second','Third','Fourth','Fifth');
array_splice($example, 3);
var_dump($example);

array
  0 => string 'First' (length=5)
  1 => string 'Second' (length=6)
  2 => string 'Third' (length=5)
于 2012-09-08T02:56:22.843 に答える
0

これを試して:

for ($i = count($array); $i > 3; $i--)
{
    array_pop($array);
}
于 2012-09-08T02:58:27.897 に答える