Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test usort() function : basic functionality --FILE-- <?php /* * Test basic funct..

Decoded Output download

*** Testing usort() : basic functionality ***

-- Numeric array with default keys --

Did this file decode correctly?

Original Code

--TEST--
Test usort() function : basic functionality
--FILE--
<?php
/*
 * Test basic functionality of usort() with indexed and associative arrays
 */

echo "*** Testing usort() : basic functionality ***\n";

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(1, 8, 9, 3, 2, 6, 7);

echo "\n-- Numeric array with default keys --\n";
var_dump( usort($int_values, 'cmp') );
var_dump($int_values);

// String array with default keys
$string_values = array("This", "is", 'a', "test");

echo "\n-- String array with default keys --\n";
var_dump( usort($string_values, 'cmp') );
var_dump($string_values);

// Associative array with numeric keys
$numeric_key_arg = array(1=> 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9);

echo "\n-- Associative array with numeric keys --\n";
var_dump( usort($numeric_key_arg, 'cmp') );
var_dump($numeric_key_arg);

// Associative array with string keys
$string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10);

echo "\n-- Associative array with string keys --\n";
var_dump( usort($string_key_arg, 'cmp') );
var_dump($string_key_arg);
?>
--EXPECT--
*** Testing usort() : basic functionality ***

-- Numeric array with default keys --
bool(true)
array(7) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(6)
  [4]=>
  int(7)
  [5]=>
  int(8)
  [6]=>
  int(9)
}

-- String array with default keys --
bool(true)
array(4) {
  [0]=>
  string(4) "This"
  [1]=>
  string(1) "a"
  [2]=>
  string(2) "is"
  [3]=>
  string(4) "test"
}

-- Associative array with numeric keys --
bool(true)
array(5) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(4)
  [3]=>
  int(7)
  [4]=>
  int(9)
}

-- Associative array with string keys --
bool(true)
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(4)
  [3]=>
  int(10)
}

Function Calls

usort 1

Variables

$int_values [{'key': 0, 'value': 1}, {'key': 1, 'value': 8}, {'key': 2, 'value': 9}, {'key': 3, 'value': 3}, {'key': 4, 'value': 2}, {'key': 5, 'value': 6}, {'key': 6, 'value': 7}]

Stats

MD5 b8a7db5486c6ab8a461b0253ad457599
Eval Count 0
Decode Time 102 ms