0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

備忘録~今日学んだ配列関係の変数まとめ~

Posted at
array_slice — 配列の一部を切り取る。
array_slice(array $array,int $offset,?int $length = null)
$input = array("a", "b", "c", "d", "e");

$output = array_slice($input, 2);      // "c", "d", "e" を返す。
$output = array_slice($input, -2, 1);  // "d" を返す。
$output = array_slice($input, 1,3); // "b", "c", "d" を返す。
$output = array_slice($input, 0, 3);   // "a", "b", "c" を返す。
array_chunk - 配列を分割する。

<?php
$input_array = array('a', 'b', 'c', 'd', 'e');
print_r(array_chunk($input_array, 2));
print_r(array_chunk($input_array, 2, true));
?>
//
Array
(
    [0] => Array
        (
            [0] => a
            [1] => b
        )
    [1] => Array
        (
            [0] => c
            [1] => d
        )
    [2] => Array
        (
            [0] => e
        )
)

Array
(
    [0] => Array
        (
            [0] => a
            [1] => b
        )
    [1] => Array
        (
            [2] => c
            [3] => d
        )
    [2] => Array
        (
            [4] => e
        )
)
array_key_exists -配列から指定のキーがあるか探す。
array_key_exists($key, $array); arrayの中にkeyがあればtrue、無ければfalseを返す。
array_merge - ひとつまたは複数の配列をくっつける。
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>
array_sum - 配列の値を足し合わせる。
array_sum($array);
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?