$ary = array("a","b","c"); print count($ary);
3
$ary = array ("a","b","c","d","e"); if (in_array("c", $ary)) { print "c があります"; } if (in_array("g", $ary)) { print "g があります"; }
c があります
$ary1 = array("a","b","c"); $ary2 = array("d","e","f"); $result = array_merge($ary1, $ary2); print_r($result);
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
)
$ary = array ("a", "b", "c"); $value = array_pop ($ary); print $value."<br />"; print_r($ary);
c
Array
(
[0] => a
[1] => b
)
$ary = array ("a", "b", "c"); array_push($ary,"d","e","f"); print_r($ary);
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
)
$ary = array ("a", "b", "c"); $value = array_shift($ary); print $value."<br />"; print_r($ary);
a
Array
(
[0] => b
[1] => c
)
$ary = array ("a", "b", "c"); array_unshift($ary,"d","e","f"); print_r($ary);
Array
(
[0] => d
[1] => e
[2] => f
[3] => a
[4] => b
[5] => c
)
array_slice(配列 , 要素位置 , 範囲)
要素位置は、正の場合は先頭から、負の場合は末尾からの位置です。
$ary = array ("a", "b", "c", "d", "e"); $result = array_slice($ary, 1, 2); print_r($result);
Array
(
[0] => b
[1] => c
)
array_splice(配列 , 要素位置 , 範囲 , 置換内容)
要素位置は、正の場合は先頭から、負の場合は末尾からの位置です。
$ary = array ("a", "b", "c", "d", "e"); array_splice ($ary, 1, 2, array("あ","い")); print_r($ary);
Array
(
[0] => a
[1] => あ
[2] => い
[3] => d
[4] => e
)