O'Reilly logo

PHP Application Development with NetBeans Beginner's Guide by M A Hossain Tonu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — adding the expression to watch

As an example, we want to test whether the same fruit name was picked again or not, by the fruit_picker() function. We may save the $myfruit value each time before a new random fruit name pick, and compare these two fruit names using an expression. So, let's add the expression watcher by using the following steps:

  1. Modify the fruit_picker() function as follows:
    function fruit_picker() {
    Global $myfruit, $fruits;
    $old_fruit = $myfruit;
    $myfruit = $fruits[rand(0, 3)];
    }
    

    We just added the line $old_fruit = $myfruit; to preserve the previous value of $myfruit, so that we can compare the previous pick in $old_fruit and the new pick in $myfruit at end of the function. We actually want to check if the same ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required