Can't Sort PHP Array -


can tell me why can't work?

i trying sort arrays highest lowest.

$stuff[] = "100"; $stuff[] = "104"; $stuff[] = "102"; $stuff[] = "103"; $stuff[] = "101"; $stuff[] = "99";  echo "largest: " . max($stuff) . " <br> \n"; arsort($stuff);  echo "0 : " . $stuff[0] . " <br> \n"; echo "1 : " . $stuff[1] . " <br> \n"; echo "2 : " . $stuff[2] . " <br> \n"; echo "3 : " . $stuff[3] . " <br> \n"; echo "4 : " . $stuff[4] . " <br> \n"; echo "5 : " . $stuff[5] . " <br> \n"; 

arsort() sorting array, conserve keys of each value. witch mean key 0 still answer 100, , not first element !

with foreach, see them in correct order.

foreach ($stuff $value) {     echo $value . "<br>\n"; } 

or

you can use rsort() not associative, mean keys won't have same values after it.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -