Use these to Order your Arrays: –
sort() – sort arrays in ascending order
rsort() – sort arrays in descending order
asort() – sort associative arrays in ascending order, according to the value
ksort() – sort associative arrays in ascending order, according to the key
arsort() – sort associative arrays in descending order, according to the value
krsort() – sort associative arrays in descending order, according to the key
1 2 3 4 5 6 |
$numbers=array(99,4,6,2,78,22,11); rsort($numbers); var_dump($numbers); |
Remove empty Arrays
This will get rid of empty array data.
1 2 3 |
print_r(array_filter($itemarray)); |
Unique – Distinct (No duplicates)
1 2 3 4 5 6 |
<?php $a=array("a"=>"red","b"=>"green","c"=>"red"); print_r(array_unique($a)); ?> |
Count
1 2 3 4 |
echo "<p>Count amount in array<br>"; echo (count($data_array)); |
Take off last element in array
1 2 3 4 5 6 7 |
<?php $a=array("red","green","blue"); array_pop($a); print_r($a); ?> |
Javascript version
Count how many in array
1 2 3 |
alert(my_array.length); |