How to get the output on this PHP script? -
i'm newbie programming , php learning 2 dimensional arrays.
when run code below, gives me blank page. when put echo in front of function call echo usort($a, 'mysort1'); page shows me 1 (i have no idea why).
what want see output of array after it's been sorted.
doing var_dump($a); not i'm after. how show result of function?
how? if can help.
<?php $a = array ( array ('key1' => 940, 'key2' => 'blah'), array ('key1' => 23, 'key2' => 'this'), array ('key1' => 894, 'key2' => 'that') ); function mysort1($x, $x) { return ($x['key1'] > $y['key']); } usort($a, 'mysort1'); ?>
for starters think have 2 typos in comparison function:
//should $y not $x function mysort1($x, $y) { return ($x['key1'] > $y['key1']); // should $y['key1'] } next, usort sorts array in place returning true on success , false otherwise, why see 1 when echo it's return value.
try:
print_r($a); to display sorted array.
Comments
Post a Comment