Make array_splice() example clearer

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@342773 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Chris Wright 2017-08-04 12:50:49 +00:00
parent daa3a5eedc
commit f9f9a44875

View file

@ -150,16 +150,27 @@ array_splice($input, 3, 0, "purple");
<programlisting role="php">
<![CDATA[
<?php
// append two elements to $input
array_push($input, $x, $y);
array_splice($input, count($input), 0, array($x, $y));
// remove the last element of $input
array_pop($input);
array_splice($input, -1);
// remove the first element of $input
array_shift($input);
array_splice($input, 0, 1);
// insert an element at the start of $input
array_unshift($input, $x, $y);
array_splice($input, 0, 0, array($x, $y));
// replace the value in $input at index $x
$input[$x] = $y; // for arrays where key equals offset
array_splice($input, $x, 1, $y);
?>
]]>
</programlisting>