[wd_asp elements=’search’ ratio=’100%’ id=1]

Sort Arrays

25th August 2014

Php - Arrays

php codehaven

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


$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.
print_r(array_filter($itemarray));

Unique – Distinct (No duplicates)

"red","b"=>"green","c"=>"red");
print_r(array_unique($a));
?>

Count


echo "

Count amount in array
";
echo (count($data_array));

Take off last element in array

Javascript version

Count how many in array
alert(my_array.length);