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
)
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
)
Example
<?php
$lan = array(1=>”PHP”,2=> “ASP”, 3=>”JSP”);
foreach($lan as $value)
if(“PHP”==$value)
echo key($lan);
?>
Output
2
Example
<?php
$lan = array(“PHP”, “ASP”, “JSP”);
if (in_array(“PHP”, $lan)) {
echo “PHP exists”;
}
?>
Output
PHP exists
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
Example
<?php
$array = array(“php”, “asp”, “jsp”, “as”, “js”);
echo end($array);
?>
Output
js
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
)
Example
<?php
$web = array(‘PHP’, ‘JSP’, ‘ASP’, ‘JS’);
echo current($web);
?>
Output
PHP
Example
<?php
$array = array(PHP,ASP);
echo count($array);
?>
Output
2
Example
<?php
echo “<pre>”;
$web = “PHP”;
$clinet = “Brwoser”;
$vars = array(“clinet”);
$array = compact(“web”, “nothing_here”, $vars);
print_r($array);
?>
Output
Array
(
[web] => PHP
[clinet] => Brwoser
)
Example
<?php
echo “<pre>”;
$array = array(‘PHP’,’ ASP’, ‘JS’,’AS’);
asort($array);
print_r($array);
?>
Output
Array
(
[1] => ASP
[3] => AS
[2] => JS
[0] => PHP
)