New Formation

range($m1, $m2[,$num=1]) returns an array with values from $m1 to $m2, with $num as the incrementing step. array_fill($i1,$i2,$m) returns an array with $i2 elements, all with value $m, starting from index $i1. array_fill_keys($arr,$m) returns an array that uses the values of $arr as keys, and uses $m as the value. array_pad($arr,$i,$m) returns a copy of $arr, padded to the size of $i with value $m. If $i >= 1 then the array is padded on the right, if $i <= -1 then on the left. If |$i| <= the length of $arr then no padding takes place.

<!DOCTYPE html><html><head></head>
<body>
<?php
print_r(range(-10,10,3)); echo "<br />";
print_r(array_fill(3,4,"HI")); echo "<br />";
$a=['smile','hello','world'];
print_r(array_fill_keys($a,"HI")); echo "<br />";
print_r(array_pad($a,-6,"HI"))
?> 
</body></html>

Array ( [0] => -10 [1] => -7 [2] => -4 [3] => -1 [4] => 2 [5] => 5 [6] => 8 )
Array ( [3] => HI [4] => HI [5] => HI [6] => HI )
Array ( [smile] => HI [hello] => HI [world] => HI )
Array ( [0] => HI [1] => HI [2] => HI [3] => smile [4] => hello [5] => world )
array_values($arr) returns an array with the values of $arr as values, indexed numerically. array_keys ($arr[,$m[,$b=false]]) returns an array with keys of $arr as values, indexed numerically. If $m is specified, then only the keys for that value are returned. If $b is true, then the types are compared as well. array_combine($arr1, $arr2) returns an array with the values of $arr1 as keys, and the values of $arr2 as the corresponding values. array_merge($arr1[,$arr2……]) returns an array that combines $arr1, $arr2…… If the input arrays have the same string keys, then the later value will overwrite the previous one. Values with numeric keys will be renumbered starting from zero. array_merge_recursive($arr1[$,arr2……])  is similar to array_merge(), except that when the input arrays have the same string keys, the values will be merged into an array. Any array values will be merged recursively. array_chunk($arr,$i [,$b=false]) returns a multidimensional array that is formed by splitting $arr into chunks, each containing $i elements. If $b is true, the keys will be preserved.

<!DOCTYPE html><html><head></head>
<body>
<?php
$a1=['apple','banana','special'=>'pear'];
$a2=['cat','dog','special'=>'fish'];
print_r(array_values($a1)); echo "<br /><br />";
print_r(array_keys($a1)); echo "<br /><br />";
print_r(array_combine($a1,$a2)); echo "<br /><br />";
print_r(array_merge_recursive($a1,$a2)); echo "<br /><br />";
print_r(array_chunk(['a','b','c','d','e'],2));
?> 
</body></html>

Array ( [0] => apple [1] => banana [2] => pear )

Array ( [0] => 0 [1] => 1 [2] => special )

Array ( [apple] => cat [banana] => dog [pear] => fish )

Array ( [0] => apple [1] => banana [special] => Array ( [0] => pear [1] => fish ) [2] => cat [3] => dog )

Array ( [0] => Array ( [0] => a [1] => b ) [1] => Array ( [0] => c [1] => d ) [2] => Array ( [0] => e ) )
array_slice($arr,$i1[,$i2[,$b=FALSE]]) returns an array which is a sequence of $i2 elements from $arr, starting from $i1. If $i1 is negative, the sequence will start that far from the end. If $i2 is negative, the sequence will stop that many elements from the end. If $i2 is omitted, the sequence will have everything from $i up until the end. If $b is true, the keys will be preserved. array_splice (&$arr1, $i1[,$i2=0[,$arr2]]) removes $i2 elements from $arr1, starting from $i1, and then inserts the elements of $arr2 into the position of removal. An array consisting of the extracted elements is returned. If $i1 is negative, the removal starts that far from the end. If $i2 is omitted, everything from $i1 to the end will be removed. If $i2 is negative, the end of the removed portion will be that many elements from the end. array_replace($arr1,$arr2[,$arr3……]) returns an array formed by replacing the values in $arr1 with values of the same keys from $arr2. If three or more arrays are passed, then the values of the later arrays will be used. array_replace_ recursive ($arr1,$arr2[,$arr3……]) is similar to array_replace(…), except that the replacement will recurse into deeper arrays, when both values are arrays.

<!DOCTYPE html><html><head></head>
<body>
<?php

$a=[1,2,3,4,5,6,7];
print_r(array_slice($a,-3,2)); echo "<br />";
print_r(array_slice($a,1,-2)); echo "<br />";

array_splice($a,2,2,[100,200,300]);
print_r($a);  echo "<br />";

$a=[1,2,3,4,5,6,7];
print_r(array_replace($a,[100,200,5=>300,400,500,600]));

?> 
</body></html>

Array ( [0] => 5 [1] => 6 )
Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 )
Array ( [0] => 1 [1] => 2 [2] => 100 [3] => 200 [4] => 300 [5] => 5 [6] => 6 [7] => 7 )
Array ( [0] => 100 [1] => 200 [2] => 3 [3] => 4 [4] => 5 [5] => 300 [6] => 400 [7] => 500 [8] => 600 )