Change the value of variable PHP
I have input fields, which I process with AJAX and send it on another file. The value of the inputs is always different. How in the file, where I get the data from AJAX, to change the variable id always when I get the data from AJAX.
Example: I get the data f开发者_开发技巧rom AJAX in this file:
<?php
$id=1;
echo '<div id="$id"></div>';
?>
Then I display the result in the page with AJAX.
I want the id of the div to be always different.
if you want $id
a random number use the function rand
link text
$id=rand(0,100); // random between 0 and 100, 0 and 100 incluse
you can also create a random string
function genRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[rand(0, strlen($characters))];
}
return $string;
}
One can create different random number through time checking, this will create random number on the basis of time and will generate different number each microseconds.
//this will add a char on the beginning of the value so it do not start with numeral
$str=range(a,z);
//using date function for generating random number
$i= $str[rand(0,25)].date('Ymzhisu');
精彩评论