Monday, 19 March 2012

Q: how can shorting array in php?


Q: how can shorting array .
Or
Q: What is shorting array 
sortSort an array
<?php
$fruits = array("lemon""orange""banana""apple");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo "fruits[" $key "] = " $val "\n";
}
?>
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
arsortSort an array in reverse order and maintain index association
<?php
$fruits = array("d" => "lemon""a" => "orange""b" => "banana""c" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}
?>
a = orange
d = lemon
b = banana
c = apple
 nextAdvance the internal array pointer of an array
<?php
$transport = array('foot''bike''car''plane');
$mode current($transport); // $mode = 'foot';
$mode next($transport);    // $mode = 'bike';
$mode next($transport);    // $mode = 'car';
$mode prev($transport);    // $mode = 'bike';
$mode end($transport);     // $mode = 'plane';
?>

No comments:

Post a Comment