0
0

More than 3 years have passed since last update.

array_slice関数

Posted at

array_slice

配列の一部の範囲をスライス(切り取る、取得する)

array_slice(array $array, int $offset [,int $lenght = NULL[, bool $preserve_keys=False]]):array

引数 

$array=>対象の配列

$offset=>取得したい要素

$lenght=>取得したい要素の数

$preservekeys=>trueのときは、引数preservekeys=>trueのときは、引数arrayのキー番号を保持した戻り値を返す。falseのときは、戻り値のキー番号は始まりになる

戻り値

offsetから$lenght分の要素

使用例

入力

$array=["a","b","c","d","e","f","g"];

echo var_dump($array);

$array_slice=array_slice($array,3,2);

echo var_dump($array_slice);

出力

array(7) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "e" [5]=> string(1) "f" [6]=> string(1) "g" }

array(2) {
  [0]=>
  string(1) "d"
  [1]=>
  string(1) "e"
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0