ksort

It sorts an array by key

Example

<?php
echo “<pre>”;
$lan = array(2=>”PHP”,1=> “ASP”, 3=>”JSP”);
ksort($lan);
print_r($lan);
?>

Output

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

krsort

It sorts an array by key in reverse order

Example

<?php
echo “<pre>”;
$lan = array(1=>”PHP”,2=> “ASP”, 3=>”JSP”);
krsort($lan);
print_r($lan);
?>

Output

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

key

It fetches a key from an array

Example

<?php
$lan = array(1=>”PHP”,2=> “ASP”, 3=>”JSP”);
foreach($lan as $value)
if(“PHP”==$value)
echo key($lan);
?>

Output

2

extract

It import variables into the current symbol table from an array

Example

<?php
$array = array(“lan”=>”php”, “server”=> “Apache”, “browser”=> “Chrome”);
extract($array);
echo $lan.”<br >”;
echo $server.”<br >”;
echo $browser.”<br >”;
?>

Output

php
Apache
Chrome

end

It sets the internal pointer of an array to its last element

Example

<?php
$array = array(“php”, “asp”, “jsp”, “as”, “js”);
echo end($array);
?>

Output

js

each

It return the current key and value pair from an array and advance the array cursor

Example

<?php
echo “<pre>”;
$array = array(“php”, “asp”, “jsp”, “as”, “js”);
$array2 = each($array);
print_r($array2);
?>

Output

Array
(
[1] => php
[value] => php
[0] => 0
[key] => 0
)