August 30, 2013

Override if condition fulfills in sleep() function in php

MR.Test’s Question:

Is it possible to write sleep function with condition in php?
Example…

Public function sleepy() {
sleep(100);
If(condition a) { 
Sleep(50);
} else {
 Echo 'some thing'
 }
}

So that the sleep(50) must be override the 100 if condition full fill?

How could I achieve similar concept, in proper programming practice?

By the way, I am typing from my iphone, sorry for any unclear code, if any…

If that is only thing you are trying to do, then just move the the sleep(100) inside the else portion.

public function sleepy() {

    if(condition a) { 
        sleep(50);
    } else {
        sleep(100);
        echo 'some thing'
    }
}

If you are really trying to override the parameter like that, you can design you own function to execute the sleep afterward instead.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!