uasort


php128 apg

SORT an ARRAY using an user-defined comparison function maintaining the index association.





This function returns TRUE on success or FALSE on failure.

This function will sort an array by its values using a user-supplied comparison function, mantaining the correlation of indexes and elements.

If two members compare as equal, their relative order in the sorted ARRAY is undefined.

This function assigns the same keys to the elements in $array.



<?php

bool uasort 
arr &$array , callable $value_compare_func )


where,

&
$array The input ARRAY

$value_compare_func The comparisson function

?> 

&$array


The input ARRAY.



$value_compare_func


An user-defined function.



  1 EXERCISE   

<?php

function recc01 $i$j )
{
return 
$i%$j;
}

$arr01u = [2818379];

echo 
'The given ARRAY:<br><pre>';
var_dump($arr01u);
echo 
'</pre>';

echo 
'<br>';

uasort($arr01u'recc01');

echo 
'The SORTED ARRAY:<br><pre>';
var_dump($arr01u);
echo 
'</pre>';

?> 

 RESULT   

The given ARRAY:
array(6) {
[0]=>
int(2)
[1]=>
int(8)
[2]=>
int(18)
[3]=>
int(3)
[4]=>
int(7)
[5]=>
int(9
)

The SORTED ARRAY:
array(6) {
[4]=>
int(7)
[2]=>
int(18)
[5]=>
int(9)
[3]=>
int(3)
[1]=>
int(8)
[0]=>
int(2)
)


  2 EXERCISE   

<?php

function recc02 $i$j )
{
return 
$j%$i;
}

$arr02u = [2818379];

echo 
'The given ARRAY:<br><pre>';
var_dump($arr02u);
echo 
'</pre>';

echo 
'<br>';

uasort($arr02u'recc02');

echo 
'The SORTED ARRAY:<br><pre>';
var_dump($arr02u);
echo 
'</pre>';

?> 

 RESULT   

The given ARRAY:
array(6) {
[0]=>
int(2)
[1]=>
int(8)
[2]=>
int(18)
[3]=>
int(3)
[4]=>
int(7)
[5]=>
int(9
)

The SORTED ARRAY:
array(6) {
[4]=>
int(7)
[3]=>
int(3)
[5]=>
int(9)
[0]=>
int(2)
[2]=>
int(18)
[1]=>
int(8)
)


  3 EXERCISE   

<?php

function recc03 $i$j )
{
return 
$j;
}

$arr03u = [ "Countries" => [ 'BRA' => "Brasil"
                                           
'POR' => "Portugal"
                                           
'JPN' => "Japan" ], 
"Continents" =>  ['SA' => "South America"
                          
'EU' => "Europe"
                          
'AS' => "Asia"]]; 

echo 
'The given ARRAY:<br><pre>';
var_dump($arr03u);
echo 
'</pre>';

echo 
'<br>';

uasort($arr03u'recc03');

echo 
'The SORTED ARRAY:<br><pre>';
var_dump($arr03u);
echo 
'</pre>';

?> 

 RESULT   

The given ARRAY:
array(2) {
["Countries"]=>
array(3) {
["BRA"]=>
string(6) "Brasil"
["POR"]=>
string(8) "Portugal"
["JPN"]=>
string(5) "Japan"
}
["Continents"]=>
array(3) {
["SA"]=>
string(13) "South America"
["EU"]=>
string(6) "Europe"
["AS"]=>
string(4) "Asia"
}
}

The SORTED ARRAY:
array(2) {
["Continents"]=>
array(3) {
["SA"]=>
string(13) "South America"
["EU"]=>
string(6) "Europe"
["AS"]=>
string(4) "Asia"
}
["Countries"]=>
array(3) {
["BRA"]=>
string(6) "Brasil"
["POR"]=>
string(8) "Portugal"
["JPN"]=>
string(5) "Japan"
}
}


  4 EXERCISE   

<?php

function recc04 $i$j )
{
echo 
$j '<br><br>' $i;
}

$arr04u = [ "english" => 'unconstitutional'
"portuguese" =>  'inconstitucional']; 

echo 
'The given ARRAY:<br><pre>';
var_dump($arr04u);

echo 
'</pre><br>The SORTED ARRAY:<br><br>';

uasort($arr04u'recc04');

?> 

 RESULT   

The given ARRAY:
array(2) {
["english"]=>
string(16) "unconstitutional"
["portuguese"]=>
string(16) "inconstitucional"
}

The SORTED ARRAY:
inconstitucional

unconstitutional


  5 EXERCISE   

<?php

function recc05($i$j)
{
return 
strcmp($i[0], $j[0]);
}

$colors[0][0] = "RED";
$colors[1][0] = "GREEN";
$colors[2][0] = "BLUE";

uasort($colors"recc05");

echo 
'<pre>';
var_dump($colors);
echo 
'</pre>';

$c count($colors) - 1;

for(
$x 0$x <= $c$x++)
{
    echo 
$x ' => ' $colors[$x][0] . '<br>';
}

?>

 RESULT   

array(3) {
[0]=>
array(1) {
[0]=>
string(4) "BLUE"
}
[1]=>
array(1) {
[0]=>
string(5) "GREEN"
}
[2]=>
array(1) {
[0]=>
string(3) "RED"
}
}

or

0 => RED
1 => GREEN
2 => BLUE


  6 EXERCISE   

<?php

echo "Testing uasort() : basic functionality.";

// comparison function
function cmp($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else
    return -
1;
}

// Int array with default keys
$int_values = array(1893267);
echo 
"<br><br>Numeric array with default keys:<br><br>";
var_dumpuasort($int_values'cmp') );
echo 
'<br><pre>';
var_dump($int_values);
echo 
'</pre>';

// String array with default keys
$string_values = array("This""is"'a'"test");
echo 
"<br><br>String array with default keys:<br><br>";
var_dumpuasort($string_values'cmp') );
echo 
'<br><pre>';
var_dump($string_values);
echo 
'</pre>';

// Associative array with numeric keys
$numeric_key_arg = array(1=> 1=> 2=> 7=> 4=> 9);
echo 
"<br><br>Associative array with numeric keys:<br><br>";
var_dumpuasort($numeric_key_arg'cmp') );
echo 
'<br><pre>';
var_dump($numeric_key_arg);
echo 
'</pre>';

// Associative array with string keys
$string_key_arg = array('one' => 4'two' => 2'three' => 1'four' => 10);
echo 
"<br><br>Associative array with string keys:<br><br>";
var_dumpuasort($string_key_arg'cmp') );
echo 
'<br><pre>';
var_dump($string_key_arg);
echo 
'</pre>';

?>

  7 EXERCISE   

<?php

echo "Testing uasort() : basic functionality 
                         with duplicate values."
;

// comparison function
function cmp($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else
    return -
1;
}

// increasing values
$int_values1 = array(112233);
echo 
"<br><br>Numeric array with 
                     increasing values:<br><br>"
;
var_dumpuasort($int_values1'cmp') );
echo 
'<br><pre>';
var_dump($int_values1);
echo 
'</pre>';

// decreasing values
$int_values2 = array(332211);
echo 
"<br><br>Numeric array with 
                      decreasing values:<br><br>"
;
var_dumpuasort($int_values2'cmp') );
echo 
'<br><pre>';
var_dump($int_values2);
echo 
'</pre>';

// increasing and decreasing values
$int_values3 = array(123321);
echo 
"<br><br>Numeric array with 
                     increasing and decreasing values:<br><br>"
;
var_dumpuasort($int_values3'cmp') );
echo 
'<br><pre>';
var_dump($int_values3);
echo 
'</pre>';

?>

  8 EXERCISE   

<?php

/*
* Testing uasort() with 'array_arg' 
* containing different reference variables
*/

// comparison function
function cmp_function($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else {
    return -
1;
  }
}

echo 
"Testing uasort() : 'array_arg' 
                      with elements as reference."
;

// different variables which are used 
// as elements of 'array_arg'
$value1 = -5;
$value2 100;
$value3 0;
$value4 = &$value1;

// array_args an array containing 
// elements with reference variables
$array_arg = array(
  
=> 10,
  
=> &$value4,
  
=> &$value2,
  
=> 200,
  
=> &$value3,
);

echo 
"<br><br>Sorting 'array_arg' containing 
                           different references:<br>"
;
echo 
'<br>';
var_dumpuasort($array_arg'cmp_function') ); 
// expecting: bool(true)
echo '<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

?>

  9 EXERCISE   

<?php

/* Testing uasort() with different 
 * associative arrays having keys as
 * string, integer, default & duplicate keys
 */

echo "Testing uasort() : sorting different associative arrays.";

// comparison function
function cmp($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else
    return -
1;
}

// Array with duplicate string and integer keys
$array_arg = array(=> 2"a" => 8
                             
"d" => 9=> 3
                              
=> 2"o" => 6
                             
"z" => -99=> 1
                             
"z" => 3);
                             
echo 
"<br><br>Array with duplicate keys:<br><br>";
var_dumpuasort($array_arg'cmp') );
echo 
'<pre>';
var_dump($array_arg);
echo 
'</pre>';

// Array with default and assigned keys
$array_arg = array(=> "Banana"
                               
=> "Mango""Orange"
                               
=> "Apple""Pineapple");
                               
echo 
"<br><br>Array with default/assigned keys:<br><br>";
var_dumpuasort($array_arg'cmp') );
echo 
'<pre>';
var_dump($array_arg);
echo 
'</pre>';

?>

  10 EXERCISE   

<?php

/*
* Testing uasort() with 'array_arg' 
* having different keys
*/

echo "Testing uasort() : Sorting array with all possible keys.";

//comparison function
function cmp_function($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return -
1;
  }
  else {
    return 
1;
  }
}

// different heredoc strings
//empty heredoc string
$empty_heredoc = <<<EOT1
EOT1;

// single line heredoc string
$simple_heredoc = <<<EOT2
simple
EOT2;

// multiline heredoc string
$multiline_heredoc = <<<EOT3
multiline heredoc with 123
and speci@! ch@r..\ncheck\talso
EOT3;

$array_arg = array(
  
// default key
  
1,  
  
//expecting: default key 0, 
  // value will be replaced by 'FALSE'

  // numeric keys
  
=> 10
  
// expecting: value will be replaced by 'TRUE'
  
-=> 9,
  
8.9 => 8,
  
012 => 7,
  
0x34 => 6,

  
// string keys
  
'key' => 5,  
  
//single quoted key
  
"two" => 4,  
  
//double quoted key
  
'' => 3,
  
"" => 2,
  
" " => 0,  
  
// space as key

  // bool keys
  
true => 15,
  
false => 5,
  
TRUE => 100,
  
FALSE => 25,

  
// null keys
  
null => 20,  
  
// expecting: value will be replaced by 'NULL'
  
NULL => 35,

  
// binary key
  
"a".chr(0)."b" => 45,
  
b"binary" => 30,

  
//heredoc keys
  
$empty_heredoc => 90,
  
$simple_heredoc => 75,
  
$multiline_heredoc => 200,
);
echo 
"<br><br>Sorted array after uasort() function call:<br><br>";
var_dumpuasort($array_arg'cmp_function') );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

?>

  11 EXERCISE   

<?php

/*
* sorting different types of 
* numeric arrays containing data 
* of following type:
*  integer, octal, hexadecimal & float
*/

// comparison function
function cmp_function($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else {
    return -
1;
  }
}

echo 
"Testing uasort() : different numeric 
                         arrays as 'array_arg'."
;

// Int array
$int_values = array(=> 3=> 2
                  
=> 100=> 150
                  
=> 25=> 350
                  
=> 0=> -3
                  
=> -1200);
                  
echo 
"<br><br>Sorting Integer array:<br><br>";
var_dumpuasort($int_values'cmp_function') );  
// expecting: bool(true)
echo '<br><pre>';
var_dump($int_values);
echo 
'</pre>';

// Octal array
$octal_values = array(=> 056=> 023
                              
=> 00=> 015
                              
=> -045=> 01
                              
=> -07);
                              
echo 
"<br><br>Sorting Octal array:<br><br>";
var_dumpuasort($octal_values'cmp_function') );
// expecting: bool(true)
echo '<br><pre>';
var_dump($octal_values);
echo 
'</pre>';

// Hexadecimal array
$hex_values = array(=> 0xAE=> 0x2B,
                       
=> 0X10=> -0xCF
                       
=> 0X12=> -0XF2);
                       
echo 
"<br><br>Sorting Hex array:<br><br>";
var_dumpuasort($hex_values'cmp_function') );
// expecting: bool(true)
echo '<br><pre>';
var_dump($hex_values);
echo 
'</pre>';

// Float array
$float_values = array( => 10.2=> 2.4,
                               
=> -3.4=> 0=> 0.5
                               
=> 7.3e3=> -9.34E-2);
                               
echo 
"<br><br>Sorting Float array:<br><br>";
var_dumpuasort($float_values'cmp_function') );
// expecting: bool(true)
echo '<br><pre>';
var_dump($float_values);
echo 
'</pre>';

// empty array
$empty_array = array();
echo 
"<br><br>Sorting empty array:<br><br>";
var_dumpuasort($empty_array'cmp_function') );
// expecting: bool(true)
echo '<br><pre>';
var_dump($empty_array);
echo 
'</pre>';

?>

  12 EXERCISE   

<?php

/*
* sorting different strings:
*  single quoted, double quoted and heredoc strings
*/

// comparison function
function cmp_function($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else {
    return -
1;
  }
}

// Different heredoc strings to be sorted
$empty_heredoc =<<<EOT
EOT;

$simple_heredoc1 =<<<EOT
Heredoc
EOT;

$simple_heredoc2 =<<<EOT
HEREDOC
EOT;

$multiline_heredoc =<<<EOT
heredoc string\twith!@# and 123
Test this!!!
EOT;


echo 
"Testing uasort() : different string arrays 
                          as 'array_arg'."
;

// Single quoted strings
$single_quoted_values = [
  
=> ' '=> 'test'
  
=> 'Hello'=> 'HELLO',
  
=> ''=> '\t'
  
=> '0'=> '123Hello'
  
=> '\''10 => '@#$%'
 
];
 
echo 
"<br><br>Sorting Single Quoted String values:<br><br>";
var_dumpuasort($single_quoted_values'cmp_function') );  
// expecting: bool(true)
echo '<br><pre>';
var_dump($single_quoted_values);
echo 
'</pre>';

// Double quoted strings
$double_quoted_values = [
  
=> " "=> "test"
  
=> "Hello"=> "HELLO",
  
=> ""=> "\t"
  
=> "0"=> "123Hello"
  
=> "\""10 => "@#$%"
 
];
 
echo 
"<br><br>Sorting Double Quoted String values:<br><br>";
var_dumpuasort($double_quoted_values'cmp_function') );  // expecting: bool(true)
echo '<br><pre>';
var_dump($double_quoted_values);
echo 
'</pre>';

// Heredoc strings
$heredoc_values = array(=> $empty_heredoc=> $simple_heredoc1=> $simple_heredoc2=> $multiline_heredoc);
echo 
"<br><br>Sorting Heredoc String values:<br><br>";
var_dumpuasort($heredoc_values'cmp_function') );  // expecting: bool(true)
echo '<br><pre>';
var_dump($heredoc_values);
echo 
'</pre>';

?>

  13 EXERCISE   

<?php

/*
* Testing uasort() with 'array_arg' 
* having different subarrays as array elements
*/

// comparison function
function cmp_function($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else {
    return -
1;
  }
}

echo 
"Testing uasort() : sorting array having 
              different subarrays.<br><br>"
;

$array_args = array(
  
=> array(210, -1),
  
=> array(100),
  
=> array(),
  
=> array(0),
  
=> array(-1),
  
=> array(-93454020),
  
=> array(''),
  
=> array("apple""Apple""APPLE""aPPle""aPpLe")
);
$temp_array $array_args;
// sorting array_arg as whole array
var_dumpuasort($temp_array'cmp_function') );
// expecting: bool(true)
echo '<br><pre>';
var_dump($temp_array);
echo 
'</pre>';

?>

  14 EXERCISE   

<?php

/*
* Passing different anonymous 
* functions as 'cmp_function'
*   arguments passed by value
*   arguments passed by reference
*/

echo "Testing uasort() : anonymous 
                    function as 'cmp_function'."
;

$cmp_function = function($value1$value2) {
    if (
$value1 == $value2) { return 0; }
    else if (
$value1 $value2) { return 1; }
    else { return -
1; }
};

$array_arg = array(=> 100
                               
=> 3
                               
=> -70
                               
=> 24
                               
=> 90);
                       
echo 
"<br><br>Anonymous 'cmp_function' 
                  with parameters passed by value:<br><br>"
;
var_dumpuasort($array_arg$cmp_function) );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

$cmp_function = function(&$value1, &$value2) {
    if (
$value1 == $value2) { return 0; }
    else if (
$value1 $value2) { return 1; }
    else { return -
1; }
};

$array_arg = array("b" => "Banana"
                               
"m" => "Mango"
                               
"a" => "Apple"
                               
"p" => "Pineapple");
                          
echo 
"<br><br>Anonymous 'cmp_function' 
                 with parameters passed by reference:<br><br>"
;
var_dumpuasort($array_arg$cmp_function ) );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';


?>

  15 EXERCISE   

<?php

/*
* Passing different built-in 
* library functions in place 
* of 'cmp_function'
*   valid comparison functions: 
*   strcmp() & strcasecmp()
*/

echo "Testing uasort() : built in function 
                                 as 'cmp_function'."
;
// Initializing variables
$array_arg = [ "b" => "Banana"
                       
"m" => "Mango"
                       
"a" => "apple"
                       
"p" => "Pineapple"
                       
"o" => "orange" ];
                       
$builtin_fun_arg $array_arg;
$languageConstruct_fun_arg $array_arg;

// Testing library functions as comparison function
echo "<br><br>Testing uasort() 
               with built-in 'cmp_function': strcasecmp():<br><br>"
;
var_dumpuasort($builtin_fun_arg'strcasecmp') );  
// expecting: bool(true)
echo '<br><pre>';
var_dump($builtin_fun_arg);
echo 
'</pre>';

echo 
"<br><br>Testing uasort() 
               with built-in 'cmp_function': strcmp():<br><br>"
;
var_dumpuasort($array_arg'strcmp') );
// expecting: bool(true)
echo '<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

?>

  16 EXERCISE   

<?php

/* Sort the entries by values 
 * user defined function.
 * Source code: ext/spl/spl_array.c
 * Alias to functions:
 */

echo "Testing ArrayObject::uasort() : basic functionality.";

// Reverse sorter
function cmp($value1$value2) {
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else
    return -
1;
}
$ao = new ArrayObject(array(2,3,1));

$ao->uasort('cmp');
echo 
'<br><pre>';
var_dump($ao);
echo 
'</pre>';

?>

  17 EXERCISE   

<?php

/* Sort the entries by values 
 * user defined function.
 * Source code: ext/spl/spl_array.c
 * Alias to functions:
 */

$ao = new ArrayObject();

try {
    
$ao->uasort();
} catch (
ArgumentCountError $e) {
    echo 
$e->getMessage() . "<br>";
}

try {
    
$ao->uasort(1,2);
} catch (
ArgumentCountError $e) {
    echo 
$e->getMessage() . "<br>";
}
?>

  18 EXERCISE   

<?php

/*
 * This testcase tests uasort() functionality 
 * with different objects
 * Objects of different classes:
 *  simple class,
 *  child class,
 *  empty class &
 *  static class
 */

echo "Testing uasort() : object functionality.";

// comparison function
function cmp_function($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else
    return -
1;
}


// Simple class with single member variable
class SimpleClass
{
  private 
$int_value;

  public function 
__construct($value) {
    
$this->int_value $value;
  }

}

// Class without any member
class EmptyClass
{
}

// Class with static member
class StaticClass
{
  public static 
$static_value;
  public function 
__construct($value) {
    
StaticClass::$static_value $value;
  }
}

// Abstract class
abstract class AbstractClass
{
  public 
$pub_value;
  public abstract function 
abstractMethod();
}

// Child class extending abstract class
class ChildClass extends AbstractClass
{
  public 
$child_value 100;
  public function 
abstractMethod() {
    
$pub_value 5;
  }
  public function 
__construct($value) {
    
$this->child_value $value;
  }
}

// Testing uasort with StaticClass 
// objects as elements of 'array_arg'
echo "<br><br>Testing uasort() 
                          with StaticClass objects:<br><br>"
;
$array_arg = array(
  
=> new StaticClass(20),
  
=> new StaticClass(50),
  
=> new StaticClass(15),
  
=> new StaticClass(70),
);
var_dumpuasort($array_arg'cmp_function') );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

// Testing uasort with EmptyClass 
// objects as elements of 'array_arg'
echo "<br><br>Testing uasort() with 
                                   EmptyClass objects:<br><br>"
;
$array_arg = array(
  
=> new EmptyClass(),
  
=> new EmptyClass(),
  
=> new EmptyClass(),
  
=> new EmptyClass(),
);
var_dumpuasort($array_arg'cmp_function') );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

// Testing uasort with ChildClass 
// objects as elements of 'array_arg'
echo "<br><br>Testing uasort() 
                           with ChildClass objects:<br><br>"
;
$array_arg = array(
  
=> new ChildClass(20),
  
=> new ChildClass(500),
  
=> new ChildClass(15),
  
=> new ChildClass(700),
);
var_dumpuasort($array_arg'cmp_function') );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

?>

  19 EXERCISE   

<?php

/*
 * Testing uasort() function with 
 * the array of objects
 * array of objects which has only one 
 * member variable & more than 
 * one member variables
 */

echo "Testing uasort() : object functionality.<br><br>";

// comparison function
function simple_cmp($value1$value2)
{
  if(
$value1 == $value2) {
    return 
0;
  }
  else if(
$value1 $value2) {
    return 
1;
  }
  else
    return -
1;
}

// comparison function for SimpleClass2 
// objects which has more than one members
function multiple_cmp($value1$value2)
{
  if(
$value1->getValue() == $value2->getValue())
    return 
0;
  else if(
$value1->getValue() > $value2->getValue())
    return 
1;
  else
    return -
1;
}

// Simple class with single member variable
class SimpleClass1
{
  private 
$int_value;

  public function 
__construct($value) {
    
$this->int_value $value;
  }
}

// Simple class with more than one member variables
class SimpleClass2
{
  private 
$int_value;
  protected 
$float_value;
  public 
$string_value;
  public function 
__construct($int$float$str) {
    
$this->int_value $int;
    
$this->float_value $float;
    
$this->string_value $str;
  }
  public function 
getValue() {
    return 
$this->int_value;
  }
}

// array of SimpleClass objects with only one member
$array_arg = array(
  
=> new SimpleClass1(10),
  
=> new SimpleClass1(1),
  
=> new SimpleClass1(100),
  
=> new SimpleClass1(50)
);
var_dumpuasort($array_arg'simple_cmp') );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

// array of SimpleClass objects having more than one members
$array_arg = array(
  
=> new SimpleClass2(23.4"mango"),
  
=> new SimpleClass2(101.2"apple"),
  
=> new SimpleClass2(52.5"orange"),
);
var_dumpuasort($array_arg'multiple_cmp') );
echo 
'<br><pre>';
var_dump($array_arg);
echo 
'</pre>';

?>