-3
I made this function to return a unique code ( it checks if already exists searching in a webservice), but when run, it is running forever, does not return me result.
public function generateuniquecode(){
function generatecode(){
$upper = implode('', range('A', 'Z')); // ABCDEFGHIJKLMNOPQRSTUVWXYZ
$nums = implode('', range(0, 9)); // 0123456789
$alphaNumeric = $upper.$nums; // ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
$code = '';
for($i = 0; $i < 6; $i++) {
$code .= $alphaNumeric[rand(0, strlen($alphaNumeric) - 1)];
}
return $code; // ex: X0XX0X
}
$exists = false;
while($exists == false) {
$code = generatecode();
$response = $this->seachcardbycode($code);
if($response['success'] == false){
if($response['data']['code'] == 1){
$exists = false;
}else{
die('code 0');
// code 0
// curl call error
}
}else{
$exists = true;
}
}
return $code;
}
The seachcardbycode function returns an array like this:
array(
"success"=>false / true,
"data"=>outro array
);
Have you tried to make the impression of the objects that the
$response
refers?– mutlei