array_push

It pushes one or more elements onto the end of array

Example

<?php
echo “<pre>”;
$array = array(“PHP”, “ASP”);
array_push($array, “JSP”, “VB”);
print_r($array);
?>

Output

Array
(
[0] => PHP
[1] => ASP
[2] => JSP
[3] => VB
)


array_pad

It pads array to the specified length with a value

Example

<?php
echo “<pre>”;
$array1 = array(2, 4,1, 3);
$array2 = array_pad($array1, 5, 0);
print_r($array2);
?>

Output

Array
(
[0] => 2
[1] => 4
[2] => 1
[3] => 3
[4] => 0
)


array_merge

It merge arrays

Example

<?php
echo “<pre>”;
$array1 =array(1 => ‘PHP’);
$array2 = array(1 => ‘ASP’);
$array3 = array_merge($array2,$array1);
print_r($array3);
?>

Output

Array
(
[0] => ASP
[1] => PHP
)


array_merge_recursive

It merges two or more arrays recursively

Example

<?php
echo “<pre>”;
$array1 = array(“PHP” => array(“WEB” => “1”), 7);
$array2 = array(17, “ASP” => array(“FAV” => “34”, “84”));
$array3 =($array1, $array2);
print_r($array3);
?>

Output

Array
(
[PHP] => Array
(
[WEB] => 1
)

[0] => 7
[1] => 17
[ASP] => Array
(
[FAV] => 34
[0] => 84
)


array_map

It applies the callback to the elements of the given arrays

Example

<?php
function squr($arg){
return($arg * $arg );
}
echo “<pre>”;
$array1 = array(1,7,5,1,9,8,4);
$array2 = array_map(“squr”, $array1);
print_r($array2);
?>

Output

Array
(
[0] => 1
[1] => 49
[2] => 25
[3] => 1
[4] => 81
[5] => 64
[6] => 16
)

array_keys

It returns all the keys or a subset of the keys of an array

Example

<?php
echo “<pre>”;
$array = array(PHP => 11, “ASP” => “22”);
print_r(array_keys($array));
?>

Output

Array
(
[0] => PHP
[1] => ASP
)

array_key_exists

It  checks if the given key or index exists in the array

Example

<?php
$array = array(‘PHP’ => 1, ‘JSP’ => 4);
if (array_key_exists(‘PHP’, $array)) echo “The ‘PHP’ element is in the array”;
?>

Output

The ‘PHP’ element is in the array