text
stringlengths
1
254
output
stringlengths
2
255
Don 't forget that numeric keys will be renumbered!
ไพ‹ 1 array_merge() ใฎไพ‹
$array1 = array(); $array2 = array(1 = "data"); $result = $array1 + $array2;
่ฟ”ใ•ใ‚Œใ‚‹้…ๅˆ—ใฏใ€ array("color" = "green", 2, 4, "a", "b", "shape" = "trapezoid", 4) ใจใชใ‚Šใพใ™ใ€‚
See also array_merge_recursive().
array_merge_recursive() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
(PHP 4 = 4.0.1)
(PHP 4 = 4.0.1)
It returns the resulting array.
array_merge_recursive() ใฏใ€ ไบŒใคไปฅไธŠใฎ้…ๅˆ—ใฎ่ฆ ็ด ใ‚’ใƒžใƒผใ‚ธใ—ใ€ๅ‰ใฎ้…ๅˆ—ใฎๆœ€ๅพŒใซใ‚‚ใ†ไธ€ใคใฎ้…ๅˆ—ใฎๅ€คใ‚’่ฟฝๅŠ ใ—ใพใ™ใ€‚ ใƒžใƒผใ‚ธใ—ใŸๅพŒใฎ้…ๅˆ—ใ‚’่ฟ”ใ—ใพใ™ใ€‚
If, however, the arrays have the same numeric key, the later value will not overwrite the original value, but will be appended.
ๅ…ฅๅŠ›้…ๅˆ—ใŒๅŒใ˜ๆ–‡ๅญ—ๅˆ—ใฎใ‚ญใƒผใ‚’ๆœ‰ใ—ใฆใ„ใ‚‹ๅ ดๅˆใ€ใ“ใ‚Œใ‚‰ใฎใ‚ญใƒผใฎๅ€คใฏ้… ๅˆ—ใซไธ€ใคใฎใƒžใƒผใ‚ธใ•ใ‚Œใพใ™ใ€‚ใ“ใ‚Œใฏๅ†ๅธฐ็š„ใซ่กŒใ‚ใ‚Œใพใ™ใ€‚ ใ“ใฎใŸใ‚ใ€ๅ€คใฎไธ€ใคใŒ้…ๅˆ—่‡ชไฝ“ใ‚’ๆŒ‡ใ—ใฆใ„ใ‚‹ๅ ดๅˆใ€ใ“ใฎ้–ขๆ•ฐใฏๅˆฅใฎ้…ๅˆ— ใฎๅฏพๅฟœใ™ใ‚‹ใ‚จใƒณใƒˆใƒชใ‚‚ใƒžใƒผใ‚ธใ—ใพใ™ใ€‚ใ—ใ‹ใ—ใ€้…ๅˆ—ใŒๅŒใ˜ๆ•ฐๅ€คใ‚ญใƒผใ‚’ๆœ‰ ใ—ใฆใ„ใ‚‹ๅ ดๅˆใ€ๅพŒใฎๅ€คใฏๅ…ƒใฎๅ€คใ‚’ไธŠๆ›ธใ›ใšใ€่ฟฝๅŠ ใ•ใ‚Œใพใ™ใ€‚
Example 1. array_merge_recursive() example
ไพ‹ 1 array_merge_recursive() ใฎไพ‹
The $result will be:
่ฟ”ใ•ใ‚Œใ‚‹้…ๅˆ—ใฏใ€ array ("color" = array ("favorite" = array ("red", "green"), "blue"), 5, 10) ใจใชใ‚Šใพใ™ใ€‚
See also array_merge().
array_merge() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
(PHP 4)
(PHP 4)
It maintains key association when sorting.
array_multisort() ใฏใ€่ค‡ๆ•ฐใฎ้…ๅˆ—ใ‚’ไธ€ๅบฆใซใ€ใพใŸ ใฏใ€ๅคšๆฌกๅ…ƒใฎ้…ๅˆ—ใ‚’ใใฎๆฌกๅ…ƒใฎไธ€ใคใงใ‚ฝใƒผใƒˆใ™ใ‚‹้š›ใซไฝฟ็”จๅฏ่ƒฝใงใ™ใ€‚ ใ“ใฎ้–ขๆ•ฐใฏใ€ใ‚ฝใƒผใƒˆใฎ้š›ใซใ‚ญใƒผใฎ็›ธ้–ขใ‚’็ถญๆŒใ—ใพใ™ใ€‚
The first array is the primary one to sort by.
ๅ…ฅๅŠ›ใฎ้…ๅˆ—ใฏใ€ใ‚ใ‚‹ใƒ†ใƒผใƒ–ใƒซใฎใ‚ซใƒฉใƒ ใง่กŒใ‚’ใ‚ฝใƒผใƒˆใ™ใ‚‹ๅ‡ฆ็†ใŒ่กŒใ‚ใ‚Œใพ ใ™ใ€‚ใ“ใ‚Œใฏใ€SQL ORDER BYๆง‹ๆ–‡ใจไผผใฆใ„ใพใ™ใ€‚ๆœ€ๅˆใฎ้…ๅˆ—ใฏใ‚ฝใƒผใƒˆใ•ใ‚Œ ใ‚‹ๆœ€ๅˆใฎ้…ๅˆ—ใงใ™ใ€‚ใใฎ้…ๅˆ—ใฎ่กŒใŒๅŒใ˜ใ ใฃใŸๅ ดๅˆใฏใ€ๆฌกใฎๅ…ฅๅŠ›้…ๅˆ—ใง ใ‚ฝใƒผใƒˆใ•ใ‚Œใ‚‹ใจใ„ใฃใŸใ‚ˆใ†ใซใชใ‚Šใพใ™ใ€‚
The argument structure of this function is a bit unusual, but flexible.
ใ“ใฎ้–ขๆ•ฐใฎๅผ•ๆ•ฐใฎๆง‹้€ ใฏใ€ใ‚„ใ‚„ไธ€่ˆฌ็š„ใงใฏใ‚ใ‚Šใพใ›ใ‚“ใŒใ€ๆŸ”่ปŸใชใ‚‚ใฎใง ใ™ใ€‚ๅ…ˆ้ ญใฎๅผ•ๆ•ฐใฏใ€้…ๅˆ—ใงใ‚ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚Šใพใ™ใ€‚ใใฎๅพŒใฎๅ„ๅผ•ๆ•ฐใซใฏใ€ ้…ๅˆ—ใพใŸใฏๆฌกใฎใƒชใ‚นใƒˆใซใ‚ใ‚‹ใ‚ฝใƒผใƒˆ็”จใƒ•ใƒฉใ‚ฐใฎใฉใกใ‚‰ใ‹ใ‚’ๆŒ‡ๅฎšใ™ใ‚‹ใ“ใจ ใŒๅฏ่ƒฝใงใ™ใ€‚
The very first argument has to be an array.
ใ‚ฝใƒผใƒˆๆ–นๆณ•ๆŒ‡ๅฎšใƒ•ใƒฉใ‚ฐ:
Subsequently, each argument can be either an array or a sorting flag from the following lists.
SORT_ASC - ๆ˜‡้ †ใซใ‚ฝใƒผใƒˆ
SORT_ASC - sort in ascending order
SORT_DESC - ้™้ †ใซใ‚ฝใƒผใƒˆ
SORT_DESC - sort in descending order
ใ‚ฝใƒผใƒˆๅž‹ใฎใƒ•ใƒฉใ‚ฐ:
SORT_REGULAR - compare items normally
SORT_REGULAR - ๆ™ฎ้€šใซๆฏ”่ผƒ
SORT_STRING - compare items as strings
SORT_NUMERIC - ๆ•ฐๅ€ค็š„ใซๆฏ”่ผƒ
No two sorting flags of the same type can be specified after each array.
SORT_STRING - ๆ–‡ๅญ—ๅˆ—ใจใ—ใฆๆฏ”่ผƒ
Returns TRUE on success or FALSE on failure.
ๅ„้…ๅˆ—ใซๅŒใ˜ๅž‹ใฎใ‚ฝใƒผใƒˆ็”จใƒ•ใƒฉใ‚ฐใ‚’ไบŒใคๆŒ‡ๅฎšใ™ใ‚‹ใ“ใจใฏๅ‡บๆฅใพใ›ใ‚“ใ€‚ ใ‚ใ‚‹ๅผ•ๆ•ฐ้…ๅˆ—ใซ้ฉ็”จใ‚’ๆŒ‡ๅฎšใ•ใ‚ŒใŸใ‚ฝใƒผใƒˆ็”จใƒ•ใƒฉใ‚ฐใŒ้ฉ็”จใ•ใ‚Œใ‚‹ใฎใฏใ€ใ ใฎ้…ๅˆ—ใฎใฟใงใ™ใ€‚ๆ–ฐใ—ใ„้…ๅˆ—ๅผ•ๆ•ฐใ‚’ๅ‡ฆ็†ใ™ใ‚‹ๅ‰ใซใƒ‡ใƒ•ใ‚ฉใƒซใƒˆใฎSORT_ASC ใŠใ‚ˆใณSORT_REGULARใซใƒชใ‚ปใƒƒใƒˆใ—ใพใ™ใ€‚
$ar1 = array ("10", 100, 100, "a"); $ar2 = array (1, 3, "2", 1); array_multisort ($ar1, $ar2);
ๆˆๅŠŸๆ™‚ใซ TRUE ใ€ๅคฑๆ•—ใ—ใŸๅ ดๅˆใซ FALSE ใ‚’่ฟ”ใ—ใพใ™ใ€‚
In this example, after sorting, the first array will contain 10, "a", 100, 100.
ไพ‹ 1่ค‡ๆ•ฐใฎ้…ๅˆ—ใ‚’ใ‚ฝใƒผใƒˆใ™ใ‚‹
The entries in the second array corresponding to the identical entries in the first array (100 and 100) were sorted as well.
ใ“ใฎไพ‹ใงใฏใ€ใ‚ฝใƒผใƒˆใฎๅพŒใงใ€ๆœ€ๅˆใฎ้…ๅˆ—ใฏใ€10,"a", 100, 100ใจใชใ‚Šใพ ใ™ใ€‚2็•ช็›ฎใฎ้…ๅˆ—ใฏใ€1, 1, "2", 3ใ‚’ๆœ‰ใ—ใพใ™ใ€‚ๆœ€ๅˆใฎ้…ๅˆ—(100ใŠใ‚ˆใณ 100)ใฎๅŒใ˜ใ‚จใƒณใƒˆใƒชใซๅฏพๅฟœใ—ใฆใ„ใ‚‹2็•ช็›ฎใฎ้…ๅˆ—ใฎใ‚จใƒณใƒˆใƒชใฏๅŒๆ™‚ใซใ‚ฝใƒผ ใƒˆใ•ใ‚Œใพใ™ใ€‚
Sorting multi-dimensional array
ไพ‹ 2ๅคšๆฌกๅ…ƒใฎ้…ๅˆ—ใ‚’ใ‚ฝใƒผใƒˆใ™ใ‚‹
In this example, after sorting, the first array will contain 10, 100, 100, "a" (it was sorted as strings in ascending order), and the second one will contain 1, 3, "2", 1 (sorted as numbers, in descending order).
ใ“ใฎไพ‹ใงใฏใ€ใ‚ฝใƒผใƒˆใ•ใ‚ŒใŸๅพŒใ€ๆœ€ๅˆใฎ้…ๅˆ—ใฏ10,100, 100, "a" (ๆ–‡ๅญ—ๅˆ— ใจใ—ใฆๆ˜‡้ †ใงใ‚ฝใƒผใƒˆใ•ใ‚Œใฆใ„ใพใ™)ใ‚’ๆœ‰ใ—ใฆใŠใ‚Šใ€2็•ช็›ฎใฎ้…ๅˆ—ใฏใ€ 1, 3, "2", 1 (ๆ•ฐๅ€คใจใ—ใฆ้™้ †ใซใ‚ฝใƒผใƒˆใ•ใ‚Œใฆใ„ใพใ™)ใจใชใฃใฆใ„ใพใ™ใ€‚
If the absolute value of pad_size is less than or equal to the length of the input then no padding takes place.
(PHP 4)
$input = array (12, 10, 9); $result = array_pad ($input, 5, 0); / / result is array (12, 10, 9, 0, 0) $result = array_pad ($input, -7, -1); / / result is array (-1, -1, -1, -1, 12, 10, 9) $result = array_pad ($input, 2, "noop"); / / not padded
array_pad() ใฏใ€ pad_size ใงๆŒ‡ๅฎšใ—ใŸ้•ท?`ใ‘ๅ€ค pad_value ใ‚’ใ†ใ‚ใฆ input ใฎใ‚ณใƒ”ใƒผใ‚’่ฟ”ใ—ใพใ™ใ€‚ pad_size ใŒๆญฃใฎๅ ดๅˆใ€้…ๅˆ—ใฎๅณๅดใŒๅŸ‹ใ‚ใ‚‰ใ‚Œใพใ™ใ€‚ ่ฒ ใฎๅ ดๅˆใ€้…ๅˆ—ใฎๅทฆๅดใŒๅŸ‹ใ‚ใ‚‰ใ‚Œใพใ™ใ€‚ pad_size ใฎ็ตถๅฏพๅ€คใŒ input ใฎ้•ทใ•ไปฅไธ‹ใฎๅ ดๅˆใ€ๅŸ‹ใ‚ใ‚‹ๅ‡ฆ็†ใฏ ่กŒใ‚ใ‚Œใพใ›ใ‚“ใ€‚
array_multisort
ไพ‹ 1 array_pad() ใฎไพ‹
(PHP 4)
(PHP 4)
If array is empty (or is not an array), NULL will be returned.
array_pop() ใฏ้…ๅˆ— array ใฎๆœ€ๅพŒใฎๅ€คใ‚’ๅ–ใ‚Šๅ‡บใ—ใฆ่ฟ”ใ—ใพใ™ใ€‚้…ๅˆ— array ใฏใ€่ฆ็ด ไธ€ใคๅˆ†็Ÿญใใชใ‚Šใพใ™ใ€‚ array ใŒ็ฉบใฎๅ ด ๅˆใ€(ใพใŸใฏใ€้…ๅˆ—ใงใชใ„ๅ ดๅˆใ€) NULL ใŒ่ฟ”ใ•ใ‚Œใพใ™ใ€‚
$stack = array ("orange", "banana", "apple", "raspberry"); $fruit = array_pop ($stack);
ไพ‹ 1 array_pop() ใฎไพ‹
Array ([0] = orange [1] = banana [2] = apple)
ใ“ใ‚Œใซใ‚ˆใ‚Šใ€ $stack ่ฆ็ด ใฏไบŒใค("orange"ใŠใ‚ˆใณ "apple")ใ ใ‘ใจใชใ‚Šใ€ $fruit ใฏ"raspberry"ใจใชใ‚Šใพใ™ใ€‚
Please read the section on Booleans for more information.
ใ“ใฎ้–ขๆ•ฐใฏ่ซ–็†ๅ€ค FALSE ใ‚’่ฟ”ใ™ๅฏ่ƒฝๆ€งใŒใ‚ใ‚Šใพใ™ใŒใ€ FALSE ใจใ—ใฆ่ฉ•ไพกใ•ใ‚Œใ‚‹ 0 ใ‚„""ใจใ„ใฃใŸๅ€คใ‚’่ฟ”ใ™ๅฏ่ƒฝๆ€งใ‚‚ใ‚ใ‚Šใพใ™ใ€‚่ฉณ็ดฐใซใคใ„ใฆใฏ ่ซ–็†ๅ€ค ใฎ็ซ ใ‚’ๅ‚็…งใ—ใฆใใ ใ•ใ„ใ€‚ใ“ใฎ้–ขๆ•ฐใฎ่ฟ”ใ‚Šๅ€คใ‚’่ชฟในใ‚‹ใซใฏ ===ๆผ”็ฎ—ๅญ ใ‚’ไฝฟ็”จใ—ใฆไธ‹ใ•ใ„ใ€‚
See also array_push(), array_shift(), and array_unshift().
array_push(), array_shift(), array_unshift() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
(PHP 4)
(PHP 4)
The length of array increases by the number of variables pushed.
array_push() ใฏใ€ array ใ‚’ใ‚นใ‚ฟใƒƒใ‚ฏใจใ—ใฆๅ‡ฆ็†ใ—ใ€ๆธกใ•ใ‚ŒใŸๅค‰ๆ•ฐใ‚’ array ใฎๆœ€ๅพŒใซๅŠ ใˆใพใ™ใ€‚้…ๅˆ— array ใฎ้•ทใ•ใฏๆธกใ•ใ‚ŒใŸๅค‰ๆ•ฐใฎๆ•ฐใ ใ‘ๅข—ๅŠ ใ—ใพใ™ใ€‚ ๅ„ var ๆฏŽใซไปฅไธ‹ใ‚’็นฐใ‚Š่ฟ”ใ™ใ“ใจใจๅŒใ˜ๅŠนๆžœใŒใ‚ใ‚Šใพใ™ใ€‚
$array[] = $var;
ๅ‡ฆ็†ๅพŒใฎ้…ๅˆ—ใฎไธญใฎ่ฆ็ด ใฎๆ•ฐใ‚’่ฟ”ใ—ใพใ™ใ€‚
Example 1. array_push() example
ไพ‹ 1 array_push() ใฎไพ‹
This example would result in $stack having the following elements:
ใ“ใฎไพ‹ใฎ็ตๆžœใ€ $stack ใซใฏใ€4ใคใฎ่ฆ็ด 1,2,"+", 3ใŒใ‚ใ‚‹ใ“ใจใซใชใ‚Šใพใ™ใ€‚
See also array_pop(), array_shift(), and array_unshift().
array_pop(), array_shift(), array_unshift() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
(PHP 4)
(PHP 4)
It takes an input array and an optional argument num_req which specifies how many entries you want to pick - if not specified, it defaults to 1.
array_rand() ใฏใ€้…ๅˆ—ใ‹ใ‚‰ไธ€ใคไปฅไธŠใฎใƒฉใƒณใƒ€ใƒ ใชใ‚จ ใƒณใƒˆใƒชใ‚’ๅ–ๅพ—ใ—ใ‚ˆใ†ใจใ™ใ‚‹ๅ ดๅˆใซๆœ‰็”จใงใ™ใ€‚ใ“ใฎ้–ขๆ•ฐใฏใ€้…ๅˆ— input ใŠใ‚ˆใณใ‚ชใƒ—ใ‚ทใƒงใƒณใจใ—ใฆ num_req ใ‚’ๅผ•ๆ•ฐใจใ—ใพใ™ใ€‚ใ“ใฎๅผ•ๆ•ฐใฏใ€ๅ–ๅพ—ใ™ ใ‚‹ใ‚จใƒณใƒˆใƒชใฎๆ•ฐใ‚’ๆŒ‡ๅฎšใ—ใพใ™ใ€‚ๆŒ‡ๅฎšใ•ใ‚Œใชใ„ๅ ดๅˆใฏใ€ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆใฎ1ใซใช ใ‚Šใพใ™ใ€‚
Otherwise, it returns an array of keys for the random entries.
ใ‚จใƒณใƒˆใƒชใ‚’ไธ€ใคใ ใ‘ๅ–ๅพ—ใ™ใ‚‹ๅ ดๅˆใ€ array_rand() ใฏ ใƒฉใƒณใƒ€ใƒ ใชใ‚จใƒณใƒˆใƒชใฎใ‚ญใƒผใ‚’่ฟ”ใ—ใพใ™ใ€‚ใใฎไป–ใฎๅ ดๅˆใฏใ€ใƒฉใƒณใƒ€ใƒ ใชใ‚จ ใƒณใƒˆใƒชใฎใ‚ญใƒผใฎ้…ๅˆ—ใ‚’่ฟ”ใ—ใพใ™ใ€‚ใ“ใ‚Œใซใ‚ˆใ‚Šใ€ใƒฉใƒณใƒ€ใƒ ใชใ‚ญใƒผใ‚’ๅ–ๅพ—ใ—ใ€ ้…ๅˆ—ใ‹ใ‚‰ๅ€คใ‚’ๅ–ๅพ—ใ™ใ‚‹ใ“ใจใŒๅฏ่ƒฝใซใชใ‚Šใพใ™ใ€‚
Don' t forget to call srand() to seed the random number generator.
ไนฑๆ•ฐ็”Ÿๆˆๅ™จใ‚’ๅˆๆœŸๅŒ–ใ™ใ‚‹ใŸใ‚ใซ srand() ใ‚’ใ‚ณใƒผใƒซใ™ ใ‚‹ใ“ใจใ‚’ๅฟ˜ใ‚Œใชใ„ใงไธ‹ใ•ใ„ใ€‚
Home
ไพ‹ 1 array_rand() ใฎไพ‹
(PHP 4 = 4.0.5)
(PHP 4 = 4.0.5)
If the optional initial is available, it will be used at the beginning of the process, or as a final result in case the array is empty.
array_reduce() ใฏใ€้…ๅˆ— input ใฎๅ„่ฆ็ด ใซ callback ้–ขๆ•ฐใ‚’็นฐใ‚Š่ฟ”ใ—้ฉ็”จใ—ใ€ ้…ๅˆ—ใ‚’ไธ€ใคใฎๅ€คใซๆธ›ใ‚‰ใ—ใพใ™ใ€‚ใ‚ชใƒ—ใ‚ทใƒงใƒณ intial ใŒๅˆฉ็”จๅฏ่ƒฝใชๅ ดๅˆใ€ๅ‡ฆ็†ใฎๆœ€ๅˆใงไฝฟ็”จใ•ใ‚ŒใŸใ‚Šใ€้…ๅˆ—ใŒ็ฉบใฎๅ ดๅˆใฎๆœ€็ต‚็ตๆžœ ใจใ—ใฆไฝฟ็”จใ•ใ‚Œใพใ™ใ€‚
Example 1. array_reduce() example
ไพ‹ 1 array_reduce() ใฎไพ‹
This will result in $b containing 15, $c containing 1200 (= 1*2*3*4*5*10), and $d containing 1.
ใ“ใ‚Œใซใ‚ˆใ‚Šใ€ $b ใฎๅ€คใฏ 15 ใจใชใ‚Šใ€ $c ใฎๅ€คใฏ 1200 (= 1*2*3*4*5*10)ใ€ใใ—ใฆใ€ $d ใฎๅ€คใฏ 1 ใจใชใ‚Šใพใ™ใ€‚
Prev
array_filter(), array_map() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
Prev
(PHP 4)
array_reverse() takes input array and returns a new array with the order of the elements reversed, preserving the keys if preserve_keys is TRUE.
array_reverse() ใฏใ€ array ใ‚’ๅผ•ๆ•ฐใจใ—ใ€่ฆ็ด ใฎ้ †็•ชใ‚’้€†ใซใ—ใŸๆ–ฐใ—ใ„้…ๅˆ—ใ‚’่ฟ”ใ—ใพใ™ใ€‚ใ“ใฎ้š›ใ€ preserve_keys ใŒ TRUE ใฎๅ ด ๅˆใฏใ‚ญใƒผใŒไฟๆŒใ•ใ‚Œใพใ™ใ€‚
Example 1. array_reverse() example
ไพ‹ 1 array_reverse() ใฎไพ‹
This makes both $result and $result_keyed have the same elements, but note the difference between the keys.
ใ“ใฎไพ‹ใซใŠใ„ใฆใ€ $result ใฏใ€ array (array ("green", "red"), 4.0, "php") ใจใชใ‚Šใพใ™ใ€‚ใ—ใ‹ใ—ใ€ $result2[0] ใฏใพใ  "php" ใงใ™ใ€‚
Array ([0] = Array ([0] = green [1] = red) [1] = 4 [2] = php) Array ([2] = Array ([0] = green [1] = red) [1] = 4 [0] = php)
ๆณจๆ„ 2็•ช็›ฎใฎใƒ‘ใƒฉใƒกใƒผใ‚ฟใฏใ€PHP 4.0.3ใง่ฟฝๅŠ ใ•ใ‚Œใพใ—ใŸใ€‚
Prev
(PHP 4 = 4.0.5)
Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise.
haystack ใซใŠใ„ใฆ needle ใ‚’ๆคœ็ดขใ—ใ€้…ๅˆ—ไธญใซ่ฆ‹ไป˜ใ‹ใฃใŸๅ ดๅˆใซใ ใฎใ‚ญใƒผใ‚’่ฟ”ใ—ใพใ™ใ€‚ใใ†ใงใชใ„ๅ ดๅˆใซ FALSE ใ‚’่ฟ”ใ—ใพใ™ใ€‚
If the optional third parameter strict is set to TRUE then the array_search() will also check the types of the needle in the haystack.
3็•ช็›ฎใฎใƒ‘ใƒฉใƒกใƒผใ‚ฟ strict ใŒ TRUE ใซ่จญๅฎšใ•ใ‚ŒใŸๅ ดๅˆใ€ array_search() ใฏ haystack ใฎไธญใซใ‚ใ‚‹ needle ใฎๅž‹ใ‚‚็ขบ่ชใ—ใพใ™ใ€‚
Please read the section on Booleans for more information.
ใ“ใฎ้–ขๆ•ฐใฏ่ซ–็†ๅ€ค FALSE ใ‚’่ฟ”ใ™ๅฏ่ƒฝๆ€งใŒใ‚ใ‚Šใพใ™ใŒใ€ FALSE ใจใ—ใฆ่ฉ•ไพกใ•ใ‚Œใ‚‹ 0 ใ‚„""ใจใ„ใฃใŸๅ€คใ‚’่ฟ”ใ™ๅฏ่ƒฝๆ€งใ‚‚ใ‚ใ‚Šใพใ™ใ€‚่ฉณ็ดฐใซใคใ„ใฆใฏ ่ซ–็†ๅ€ค ใฎ็ซ ใ‚’ๅ‚็…งใ—ใฆใใ ใ•ใ„ใ€‚ใ“ใฎ้–ขๆ•ฐใฎ่ฟ”ใ‚Šๅ€คใ‚’่ชฟในใ‚‹ใซใฏ ===ๆผ”็ฎ—ๅญ ใ‚’ไฝฟ็”จใ—ใฆไธ‹ใ•ใ„ใ€‚
See also array_keys() and in_array().
in_array() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
(PHP 4)
(PHP 4)
All numerical array keys will be modified to start counting from zero while literal keys won 't be touched.
array_shift() ใฏใ€ array ใฎๆœ€ๅˆใฎๅ€คใ‚’ๅ–ใ‚Šๅ‡บใ—ใฆ่ฟ”ใ—ใพใ™ใ€‚้…ๅˆ— array ใฏใ€่ฆ็ด ไธ€ใคๅˆ†ใ ใ‘็Ÿญใใชใ‚Šใ€ๅ…จใฆใฎ่ฆ็ด ใฏๅ‰ใซใšใ‚Œใพใ™ใ€‚ array ใŒ็ฉบใฎๅ ดๅˆ(ใพใŸใฏ้…ๅˆ—ใงใชใ„ๅ ดๅˆ)ใ€ NULL ใŒ่ฟ”ใ•ใ‚Œใพใ™ใ€‚
Example 1. array_shift() example
ไพ‹ 1 array_shift() ใฎไพ‹
This would result in $stack having 3 elements left:
array_unshift(), array_push(), array_pop() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
array_slice() returns the sequence of elements from the array array as specified by the offset and length parameters.
(PHP 4)
If offset is negative, the sequence will start that far from the end of the array.
array_slice() ใฏใ€ array ใ‹ใ‚‰ใƒ‘ใƒฉใƒกใƒผใ‚ฟ offset ใŠใ‚ˆใณ length ใงๆŒ‡ๅฎšใ•ใ‚ŒใŸ้€ฃ็ถšใ™ใ‚‹่ฆ็ด ใ‚’่ฟ”ใ—ใพใ™ใ€‚
If length is given and is negative then the sequence will stop that many elements from the end of the array.
offset ใŒๆญฃใฎๅ ดๅˆใ€่ฆ็ด ไฝ็ฝฎใฎ่จˆ็ฎ—ใฏใ€ ้…ๅˆ— array ใฎoffsetใ‹ใ‚‰ๅง‹ใ‚ใ‚‰ใ‚Œใพใ™ใ€‚ offset ใŒ่ฒ ใฎๅ ดๅˆใ€่ฆ็ด ไฝ็ฝฎใฎ่จˆ็ฎ—ใฏ array ใฎๆœ€ๅพŒใ‹ใ‚‰่กŒใ‚ใ‚Œใพใ™ใ€‚
Note that array_slice() will ignore array keys, and will calculate offsets and lengths based on the actual positions of elements within the array.
length ใŒๆŒ‡ๅฎšใ•ใ‚Œใ€ๆญฃใฎๅ ดๅˆใ€ ้€ฃ็ถšใ™ใ‚‹่ค‡ๆ•ฐใฎ่ฆ็ด ใŒ่ฟ”ใ•ใ‚Œใพใ™ใ€‚ length ใŒ ๆŒ‡ๅฎšใ•ใ‚Œใ€่ฒ ใฎๅ ดๅˆใ€้…ๅˆ—ใฎๆœซๅฐพใ‹ใ‚‰้€ฃ็ถšใ™ใ‚‹่ค‡ๆ•ฐใฎ่ฆ็ด ใŒ่ฟ”ใ•ใ‚Œใพใ™ใ€‚ ็œ็•ฅใ•ใ‚ŒใŸๅ ดๅˆใ€ offset ใ‹ใ‚‰้…ๅˆ—ใฎๆœ€ๅพŒใพใง ใฎๅ…จใฆใฎ่ฆ็ด ใŒ่ฟ”ใ•ใ‚Œใพใ™ใ€‚
Prev
array_splice() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
(PHP 4)
(PHP 4)
It returns an array containing the extracted elements.
array_splice() ใฏใ€้…ๅˆ— input ใ‹ใ‚‰ offset ใŠใ‚ˆใณ length ใง ๆŒ‡ๅฎšใ•ใ‚ŒใŸ่ฆ็ด ใ‚’ๅ‰Š้™คใ—ใ€้…ๅˆ— replacement ใŒ ๆŒ‡ๅฎšใ•ใ‚ŒใŸใ“ใฎ่ฆ็ด ใง็ฝฎๆ›ใ—ใพใ™ใ€‚
If offset is negative then it starts that far from the end of the input array.
offset ใŒๆญฃใฎๅ ดๅˆใ€ๅ‰Š้™คใ•ใ‚Œใ‚‹้ƒจๅˆ†ใฏ ้…ๅˆ— input ใฎๆœ€ๅˆใ‹ใ‚‰ๆŒ‡ๅฎšใ‚ชใƒ•ใ‚ปใƒƒใƒˆใฎไฝ็ฝฎ ใ‹ใ‚‰ใจใชใ‚Šใพใ™ใ€‚ offset ใŒ่ฒ ใฎๅ ดๅˆใ€ๅ‰Š้™คใ•ใ‚Œใ‚‹้ƒจๅˆ†ใฏใ€ input ใฎๆœซๅฐพใ‹ใ‚‰ๆ•ฐใˆใŸไฝ็ฝฎใ‹ใ‚‰ใจใชใ‚Šใพใ™ใ€‚
Tip: to remove everything from offset to the end of the array when replacement is also specified, use count( $input) for length.
length ใŒ็œ็•ฅใ•ใ‚ŒใŸๅ ดๅˆใ€ offset ใ‹ใ‚‰้…ๅˆ—ใฎๆœ€ๅพŒใพใงใŒๅ…จใฆๅ‰Š้™คใ•ใ‚Œใพใ™ใ€‚ length ใŒๆŒ‡ๅฎšใ•ใ‚Œใ€ๆญฃใฎๅ ดๅˆใ€่ค‡ๆ•ฐใฎ่ฆ็ด ใŒ ๅ‰Š้™คใ•ใ‚Œใพใ™ใ€‚ length ใŒๆŒ‡ๅฎšใ•ใ‚Œใ€่ฒ ใฎๅ ดๅˆใ€ๅ‰Š้™คใ•ใ‚Œใ‚‹ ้ƒจๅˆ†ใฏ้…ๅˆ—ใฎๆœซๅฐพใ‹ใ‚‰่ค‡ๆ•ฐใฎ่ฆ็ด ใจใชใ‚Šใพใ™ใ€‚ ใƒ’ใƒณใƒˆ: replacement ใ‚‚ๆŒ‡ๅฎšใ—ใŸๅ ดๅˆใซ offset ใ‹ใ‚‰้…ๅˆ—ใฎๆœ€ๅพŒใพใงๅ…จใฆใ‚’ๅ‰Š้™คใ™ใ‚‹ใซใฏใ€ length ใ‚’ๆฑ‚ใ‚ใ‚‹ใŸใ‚ใซ count($input) ใ‚’ไฝฟ็”จใ—ใฆไธ‹ใ•ใ„ใ€‚
If offset and length are such that nothing is removed, then the elements from the replacement array are inserted in the place specified by the offset.
้…ๅˆ— replacement ใŒๆŒ‡ๅฎšใ•ใ‚ŒใŸๅ ดๅˆใ€ ๅ‰Š้™คใ•ใ‚ŒใŸ่ฆ็ด ใฏใ€ใ“ใฎ้…ๅˆ—ใฎ่ฆ็ด ใง็ฝฎๆ›ใ•ใ‚Œใพใ™ใ€‚ offset ใŠใ‚ˆใณ length ใง ไฝ•ใ‚‚ๅ‰Š้™คใ—ใชใ„ใจๆŒ‡ๅฎšใ—ใŸๅ ดๅˆใ€้…ๅˆ— replacement ใฎ ่ฆ็ด ใฏ offset ใงๆŒ‡ๅฎšใ•ใ‚ŒใŸไฝ็ฝฎใซๆŒฟๅ…ฅใ•ใ‚Œใพใ™ใ€‚ ใƒ’ใƒณใƒˆ:replacementใซไธ€ใคใ—ใ‹่ฆ็ด ใŒใชใ„ๅ ดๅˆใ€่ฆ็ด ใใฎใ‚‚ใฎใŒ้…ๅˆ—ใง ใชใ„้™ใ‚Šใ€ array() ใงๆ‹ฌใ‚‹ๅฟ…่ฆใฏใ‚ใ‚Šใพใ›ใ‚“ใ€‚
The following equivalences hold:
ไปฅไธ‹ใฏ็ญ‰ไพกใจใชใ‚Šใพใ™ใ€‚
Example 1. array_splice() examples
ๅ‰Š้™คใ•ใ‚ŒใŸ่ฆ็ด ใ‹ใ‚‰ใชใ‚‹้…ๅˆ—ใ‚’่ฟ”ใ—ใพใ™ใ€‚
Prev
ไพ‹ 1 array_splice() ใฎไพ‹
array_slice
array_slice() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
array_sum() returns the sum of values in an array as an integer or float.
(PHP 4 = 4.0.4)
$a = array( 2, 4, 6, 8); echo "sum(a) = ".array_sum($a) ."\n"; $b = array("a"= 1.2 ,"b"= 2.3 ,"c"= 3.4); echo "sum(b) = ".array_sum($b) ."\n";
array_sum() ใฏใ€้…ๅˆ—ใฎไธญใฎๅ€คใฎๅˆ่จˆใ‚’ๆ•ดๆ•ฐใพใŸใฏ floatใจใ—ใฆ่ฟ”ใ—ใพใ™ใ€‚
sum( a) = 20 sum(b) = 6.9
ไพ‹ 1 array_sum() ใฎไพ‹
Prev
ๆณจๆ„ 4.0.6ใ‚ˆใ‚Šๅ‰ใฎใƒใƒผใ‚ธใƒงใƒณใฎPHPใฏใ€ๆธกใ•ใ‚ŒใŸ้…ๅˆ—่‡ชไฝ“ใ‚’ไฟฎๆญฃใ—ใ€ๆ–‡ๅญ—ๅˆ—ใ‚’ ๆ•ฐๅ€ค(ใ“ใ‚Œใฏๅ€คใซใ‚‚ใ‚ˆใ‚‹ใŒๅคšใใฎๅ ดๅˆใ‚ผใƒญใจใชใ‚Šใพใ™)ใซๅค‰ๆ›ใ—ใฆใ„ใพใ—ใŸใ€‚
Prev
(PHP 4 = 4.0.1)
array_unique() takes input array and returns a new array without duplicate values.
array_unique() ใฏใ€ array ใ‚’ๅ…ฅๅŠ›ใจใ—ใ€ๅ€คใซ้‡่ค‡ใฎใชใ„ๆ–ฐ่ฆ้…ๅˆ—ใ‚’ ่ฟ”ใ—ใพใ™ใ€‚
It does not mean that the key of the first related value from the unsorted array will be kept.
ใ‚ญใƒผใฏไฟๆŒใ•ใ‚Œใ‚‹ใ“ใจใซๆณจๆ„ใ—ใฆไธ‹ใ•ใ„ใ€‚ array_unique() ใฏใพใšๆ–‡ๅญ—ๅˆ—ใจใ—ใฆๅ€คใ‚’ใ‚ฝใƒผใƒˆใ—ใ€ ๅ„ๅ€คใฎๆœ€ๅˆใฎใ‚ญใƒผใ‚’ไฟๆŒใ—ใ€2ๅ›ž็›ฎไปฅ้™ใฎๅ…จใฆใฎใ‚ญใƒผใ‚’็„ก่ฆ–ใ—ใพใ™ใ€‚ ใ“ใ‚Œใฏใ€ใ‚ฝใƒผใƒˆๅ‰ใฎ array ใงๆœ€ๅˆใฎ้–ข้€ฃใ™ใ‚‹ๅ€คใฎ ใ‚ญใƒผใŒไฟๆŒใ•ใ‚Œใ‚‹ใจใ„ใ†ๆ„ๅ‘ณใงใฏใ‚ใ‚Šใพใ›ใ‚“ใ€‚
In words: when the string representation is the same.
ๆณจๆ„ (string) $elem1 === (string) $elem2 ใฎๅ ดๅˆใฎใฟ ไบŒใคใฎ่ฆ็ด ใฏ็ญ‰ใ—ใ„ใจใฟใชใ•ใ‚Œใพใ™ใ€‚่จ€ใ„ๆ›ใˆใ‚‹ใจใ€ๆ–‡ๅญ—ๅˆ—่กจ็พใŒ ๅŒใ˜ๅ ดๅˆใจใชใ‚Šใพใ™ใ€‚
Warning
ๆœ€ๅˆใฎ่ฆ็ด ใŒไฝฟ็”จใ•ใ‚Œใพใ™ใ€‚
Example 1. array_unique() example
ใ“ใฎ้–ขๆ•ฐใฏใ€PHP 4.0.4ใงใฏไฝฟ็”จใงใใพใ›ใ‚“!
This will output:
ไพ‹ 1 array_unique() ใฎไพ‹
Example 2. array_unique() and types
ๅ‡บๅŠ›ใฏไปฅไธ‹ใฎใ‚ˆใ†ใซใชใ‚Šใพใ™ใ€‚
The printout of the program above will be (PHP 4.0.6):
ไพ‹ 2 array_unique() ใจๅž‹
Prev
ไธŠใฎใƒ—ใƒญใ‚ฐใƒฉใƒ ใฎๅ‡บๅŠ›ใฏไปฅไธ‹ใฎใ‚ˆใ†ใซใชใ‚Šใพใ™(PHP 4.0.6)ใ€‚
array_unshift() prepends passed elements to the front of the array.
(PHP 4)
All numerical array keys will be modified to start counting from zero while literal keys won 't be touched.
array_unshift() ใฏใ€ array ใฎๅ…ˆ้ ญใซๆŒ‡ๅฎšใ•ใ‚ŒใŸ่ฆ็ด ใ‚’ๅŠ ใˆใพใ™ใ€‚ใƒชใ‚นใƒˆใฎ่ฆ็ด ใฏๅ…จไฝ“ใจใ—ใฆๅŠ ใˆใ‚‰ใ‚Œใ‚‹ใŸใ‚ใ€ ๅŠ ใˆใ‚‰ใ‚ŒใŸ่ฆ็ด ใฎ้ †็•ชใฏๅค‰ใ‚ใ‚‰ใชใ„ใ“ใจใซๆณจๆ„ใ—ใฆใใ ใ•ใ„ใ€‚
Example 1. array_unshift() example
ๅ‡ฆ็†ๅพŒใฎ array ใฎ่ฆ็ด ใฎๆ•ฐใ‚’่ฟ”ใ—ใพใ™ใ€‚
This would result in $queue having the following elements:
ไพ‹ 1 array_unshift() ใฎไพ‹
See also array_shift(), array_push(), and array_pop().
array_shift(), array_push(), array_pop() ใ‚‚ๅ‚็…งไธ‹ใ•ใ„ใ€‚
array_values() returns all the values from the input array.
(PHP 4)
$array = array ("size "= "XL", "color" = "gold"); print_r(array_values ($array));
array_values() ใฏใ€้…ๅˆ— input ใ‹ใ‚‰ๅ…จใฆใฎๅ€คใ‚’่ฟ”ใ—ใพใ™ใ€‚