Natural Order String Comparison
<?php
str str_shuffle ( str $str )
where,
$str = The STRING to be shuffled
?>
<?php
$str01 = "There's no smoke without fire!'";
/*
Try also:
$str01 = 'There\'s no smoke without fire!';
*/
$shuffld01 = str_shuffle($str01);
echo $shuffld01 . '<br><br>';
?>
<?php
$str02 = '1234567890';
$shuffld02 = str_shuffle($str02);
echo $shuffld02 . '<br><br>';
echo 'Shuffled value:<br>';
var_dump($shuffld02);
echo '<br><br>Given value:<br>';
var_dump($str02);
?>
<?php
/*
* Testing str_shuffle() : basic functionality
*/
echo "Testing str_shuffle() : basic functionality.<br>";
// Initialize all required variables
$str = 'This testcase tests the
str_shuffle() function.';
/*
// Try also:
$str = "This testcase tests the
str_shuffle() function.";
*/
$strs = str_shuffle($str);
echo "<br>Given string:<br>'$str'<br><br>
Shuffled string:<br>'$strs'<br><br>";
// For a given i/p string ensure that
// all combinations are
// generated given a reasonable
// sample of calls
$a = array();
$trys = 1000;
$ip = 'abcd';
$len_ip = strlen($ip);
for ($i = 0; $i < $trys; $i++) {
$op = str_shuffle($ip);
if (!is_string($op) || strlen($op) != $len_ip) {
echo "TEST FAILED<br>";
}
// Combination already hit ?
if (empty($a[$op])) {
// No first time init
$a[$op] = 0;
}
// Increment count for this combination
$a[$op]++;
}
$combinations = count($a);
if ($combinations != 24) {
echo "TEST FAILED..
Only $combinations out of a possible
24 combinations used<br>";
} else {
echo "TEST PASSED<br>";
}
?>
<?php
$str04 = "123âáàAGHéñÑíÕôúÚ";
/*
Try also:
$str04 = '123âáàAGHéñÑíÕôúÚ';
*/
$shuffld04 = str_shuffle($str04);
echo $shuffld04 . '<br><br>';
?>