Adhy KunKun Adhy KunKun - 2 years ago 154
PHP Question

Looping function if the function result is empty

I am confused to solve my code...
Somebody, can you please help me...

Here is my code, so far...

$r = get_pht_desc($wordString);

if (empty($r)) {

while (count($r) < 1 ) {
$r1 = get_pht_desc($wordString);
print_r ($r1);

} else {
print_r ($r);

What I want is :

If the result of my Function $r = get_pht_desc($wordString) is empty, it will repeat the function until the result is not empty or greater than zero.

Note: result of $r is an array, so I used count to check if the result is empty or not

I tried a lot of way, I think it's the way but still didn't work.
The while function gave me result

Array ( ) Array ( ) Array ( ) Array ( )....

Until Unlimited...

Thanks before.

Answer Source

USe Below Code

$r = array();
while (empty($r)) {
    $r = get_pht_desc($wordString);
print_r ($r);   

but i think it will be endless loop is get_pht_desc($wordString) return empty result bcoz might every time it return same results.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download