-2

The code below is not working Indexed arrays work fine, Look Out World

<?php
//sorting an Associative array

$age=array("peter"=>"19", "john"=>"18, "alex"=>"17");
asort($age);    


//looping an associative array

foreach($age as $x=>$x_value)
{
    echo "Name = " .$x. "age = " .$x_value. "<br>";
 } 
?>

</body>
</html>
Sugumar Venkatesan
  • 4,019
  • 8
  • 46
  • 77

1 Answers1

1

there is an syntax error , you havent closed and double quotes

$age=array("peter"=>"19", "john"=>"18", "alex"=>"17");
asort($age);

More over age can be given as an integar

$age=array("peter"=>19, "john"=>18, "alex"=>17);
asort($age);
A.B
  • 20,110
  • 3
  • 37
  • 71