Sort the array in descending order

I need to sort the array in descending order. I use asort in order to save proper reference to keys. However, $ind is null. Why?

$selected = array();

for ($i=0; $i<10; $i++) {
    $selected[] = array('ind' => $i, 'rank' => rand(0,10));

asort($selected, SORT_NUMERIC);

$ind = $selected['ind'];


After your for() loop you have something like this:

Array ( 
   [0] => Array (
      [ind] => NUM
      [rank] => NUM 
   [1] => Array (
      [ind] => NUM
      [rank] => NUM

This is called a multidimensional array, and you access the inner arrays in a similar way as you do single-dimensional arrays.

You can access it with a $array[0]['ind'], or possibly even a foreach() loop so you get all the values.

$ind = array();
foreach($array as $line) {
   $ind[] = $line['ind'];

Now the $ind array has all the values in a single-dimensional array, that you can access with: $ind[0] or $ind[1], giving you the ind value.

Need Your Help

Java snippet output not understood, probably related to polymorphism

java polymorphism

I was wondering why this bit of Java yields 2, and not 3 :

Associate file type/extension to non document based cocoa application

objective-c xcode osx file-type associate

This is for some reason really hard to find and solve. Cannot find any documentation on it.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.