How to create an array that has a range of values
$numbers = range(1, 4);
$numbers = range(10, 22, 4);
How to fill and pad an array
$numbers = array_fill(0, 5, 1);
How to merge two arrays
$employees = array('Mike', 'Anne');
$new_hires = array('Ray', 'Pren');
$employees = array_merge($employees, $new_hires);
print_r($employees); // Array ( [0] => Mike [1] => Anne [2] => Ray [3] => Pren )
");
print_r($employees); // Array ( [0] => Mike [1] => Anne [2] => Ray [3] => Pren )
echo("\n");
?>
How to slice one array from another
$employees = array('Mike', 'Anne', 'Ray', 'Pren');
$new_hires = array_slice($employees, 2);
print_r($new_hires); // Array ( [0] => Mike [1] => Anne [2] => Ray [3] => Pren )
How to splice two arrays together
$employees = array('Mike', 'Anne', 'Joel');
$new_hires = array('Ray', 'Pren');
array_splice($employees, 1, 2, $new_hires);
print_r($employees); // Array ( [0] => Ray [1] => Pren )
");
print_r($employees); // Array ( [0] => Ray [1] => Pren )
echo("\n");
?>
Back