Tag Archives: Array

reset

it  set the internal pointer of an array to its first element

Example

<?php
$lan = array(“PHP”,”JSP”,”ASP”);
next($lan);
next($lan);
echo reset($lan);
?>

Output

PHP

Share

range

It can be used to create an array containing a range of elements

Example

<?php
echo “<pre>”;
$array = range(3, 7);
print_r($array);
?>

Output

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

Share

prev

It rewinds the internal array pointer

Example

<?php
$lan = array(“PHP”,”JSP”,”ASP”);
next($lan);
echo prev($lan);
?>

Output

PHP

Share

natsort

It sorts an array using a “natural order” algorithm

Example

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

Output

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

Share

natcasesort

It sorts an array using a case insensitive “natural order” algorithm

Example

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

Output

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

Share

list

It assigns variables as if they were an array

Example

<?php
echo “<pre>”;
$lan = array(“PHP”,”ASP”,”JSP”);
list($lan1, $lan2, $lan3) = $lan;
echo $lan1.”<br>”;
echo $lan2.”<br>”;
echo $lan3.”<br>”;
?>

Output

PHP
ASP
JSP

Share

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
)

Share

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
)

Share