add tag
David (imported from SE)
I have read as widely about `usort` as I can, but I cannot work out this one. It might be that `usort` is not the tool I need? Here's a bit of the array that I'm working with (I have it assigned to `$allPages`):

```php
	Array
	(
		[0] => Page Object
			(
				[id] => 4
				[slug] => articles
				[created_on] => 2009-08-06 07:16:00
			)

		[1] => Page Object
			(
				[id] => 99
				[slug] => a-brief-history
				[created_on] => 2011-04-25 12:07:26
			)

		[2] => Page Object
			(
				[id] => 98
				[slug] => we-arrive
				[created_on] => 2011-04-24 13:52:35
			)

		[3] => Page Object
			(
				[id] => 83
				[slug] => new-year
				[created_on] => 2011-01-02 14:05:12
			)
	)
```

I am trying ultimately to sort on the `created_on` value, but for the moment, I'd settle on being able to sort on any of them! When I try the normal `cmp($a, $b)` type callback with `usort` -- as, for example, in [this answer on a SO usort question](https://stackoverflow.com/questions/3072445/sorting-by-a-specific-key-of-a-multi-dimensional-array-php/3072489#3072489) -- I just get a blank. Example:

```php
    function cmp($a, $b) {
      return strcmp($a["slug"], $b["slug"]);
    }
    usort($allPages, 'cmp')
```

And `print_r` gives me nothing. This is with PHP 5.2.n, not 5.3 btw. 

Guidance, please? And thankyou!
Top Answer
Kelly (imported from SE)
Your items in the array are objects, not associative arrays, so you need to refer to them like this:

    function cmp($a, $b) {
      return strcmp($a->slug, $b->slug);
    }
    usort($allPages, 'cmp')

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.