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 uasort() function : usage variations - sort diff. strings --FILE-- <?php /* ..

Decoded Output download

*** Testing uasort() : different string arrays as 'array_arg' ***
-- Sorting Single Quoted String values --

Did this file decode correctly?

Original Code

--TEST--
Test uasort() function : usage variations - sort diff. strings
--FILE--
<?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' ***\n";

// Single quoted strings
$single_quoted_values = array(
  0 => ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO',
  5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 9 => '\'', 10 => '@#$%'
);
echo "-- Sorting Single Quoted String values --\n";
var_dump( uasort($single_quoted_values, 'cmp_function') );  // expecting: bool(true)
var_dump($single_quoted_values);

// Double quoted strings
$double_quoted_values = array(
  0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO",
  5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 9 => "\"", 10 => "@#$%"
);
echo "-- Sorting Double Quoted String values --\n";
var_dump( uasort($double_quoted_values, 'cmp_function') );  // expecting: bool(true)
var_dump($double_quoted_values);

// Heredoc strings
$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 2 => $simple_heredoc2, 3 => $multiline_heredoc);
echo "-- Sorting Heredoc String values --\n";
var_dump( uasort($heredoc_values, 'cmp_function') );  // expecting: bool(true)
var_dump($heredoc_values);

echo "Done"
?>
--EXPECTF--
*** Testing uasort() : different string arrays as 'array_arg' ***
-- Sorting Single Quoted String values --
bool(true)
array(10) {
  [5]=>
  string(0) ""
  [0]=>
  string(1) " "
  [9]=>
  string(1) "'"
  [7]=>
  string(1) "0"
  [8]=>
  string(8) "123Hello"
  [10]=>
  string(4) "@#$%"
  [4]=>
  string(5) "HELLO"
  [3]=>
  string(5) "Hello"
  [6]=>
  string(2) "\t"
  [1]=>
  string(4) "test"
}
-- Sorting Double Quoted String values --
bool(true)
array(10) {
  [5]=>
  string(0) ""
  [6]=>
  string(1) "	"
  [0]=>
  string(1) " "
  [9]=>
  string(1) """
  [7]=>
  string(1) "0"
  [8]=>
  string(8) "123Hello"
  [10]=>
  string(4) "@#$%"
  [4]=>
  string(5) "HELLO"
  [3]=>
  string(5) "Hello"
  [1]=>
  string(4) "test"
}
-- Sorting Heredoc String values --
bool(true)
array(4) {
  [0]=>
  string(0) ""
  [2]=>
  string(7) "HEREDOC"
  [1]=>
  string(7) "Heredoc"
  [3]=>
  string(4%d) "heredoc string	with!@# and 123
Test this!!!"
}
Done

Function Calls

uasort 1

Variables

$empty_heredoc
$simple_heredoc1 Heredoc
$simple_heredoc2 HEREDOC
$multiline_heredoc heredoc string with!@# and 123 Test this!!!
$single_quoted_values [{'key': 0, 'value': ' '}, {'key': 1, 'value': 'test'}, {'key': 3, 'value': 'Hello'}, {'key': 4, 'value': 'HELLO'}, {'key': 5, 'value': ''}, {'key': 6, 'value': '\\t'}, {'key': 7, 'value': '0'}, {'key': 8, 'value': '123Hello'}, {'key': 9, 'value': "'"}, {'key': 10, 'value': '@#$%'}]

Stats

MD5 29779a804e5c2267d684aca211eb29d3
Eval Count 0
Decode Time 84 ms