I am trying to work out to put the contents of a variable into an array(string array) and to generate a random number from it.
Ex : if i type "ABCA " as the input in the message box the out put has to be "BCDB". But the output shows as BBCD(looks liketo an alphebatical order).
I tried to eleminate that by assinging the contents of the value of the variable $value into an array and they 'krsort 'it. It gives me warnings.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Warning: krsort() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 16
B
Warning: array_rand() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 19
Warning: krsort() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 16
B
Warning: array_rand() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 19
Warning: krsort() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 16
C
Warning: array_rand() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 19
Warning: krsort() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 16
D
Warning: array_rand() expects parameter 1 to be array, string given in C:\wamp\www\pin project\Codelobster1.php on line 19
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code: Select all
<?php
if (isset($_POST['submit1']))
{
$message = $_POST['Message'];
//$array1=array('A','C','B','A');
$str= str_split($message);
$array = array('A'=>'B','B'=>'C','C'=>'D');
foreach($array as $key=>$value){
for($i=0;$i<count($str);$i++){
if($key==$str[$i]){
//assigns the contents of the value variable into an array.
$value==array();
krsort($value);
echo"$value";
//generates a random number;
$random = array_rand($value);
echo"$random";
}
}
}
}
echo"
<form action='Codelobster1.php' method='POST' >
<td>
<tr>
<td>
<font SIZE = 5 FACE = times new roman >Message</font>
</td>
<td>
<input type='text' name='Message' maxlength='30'>
</td>
</tr>
</td>
<tr>
<td align='center' valign='top' colspan='2'>
<input type='submit' name='submit1' value='Confirm'>
</td>
</tr>
</form>";
?>Shehan31