php - if condition is true goto the start of the program -


i have piece of code, if "if" statement in code inside function "minmax" true, want program start beginning. not sure how implement logic, can please help

<?php  // user enter number of heads echo "enter number of heads: " . php_eol; // script wait here until user has entered , hit enter $inhead = read_stdin(); // user enter number of legs echo "enter number of legs: " . php_eol; // script wait here until user has entered , hit enter $inleg = read_stdin(); function read_stdin() {     $fr=fopen("php://stdin","r");   // open our file pointer read stdin     $input = fgets($fr,128);        // read maximum of 128 characters     $input = rtrim($input);         // trim trailing spaces.     fclose ($fr);                   // close file handle     return $input;                  // return text entered } //function evalute if th euser has provided right number of legs function minmax($number) {     global $inhead,$inleg;     $min = 2*$inhead;     $max = 4*$inhead;     if ($number<$min || $number>$max)     {         echo "please enter number between $min , $max correct result";         echo "\n";         echo "\n";     } }  //function calculate number of heads , legs function get_the_result($noofheads,$nooflegs) {        $x=($nooflegs-(2*$noofheads))/2;     $y=$noofheads - $x;     echo "the num of dogs $x";     //echo "/n";     echo "the no of humans $y"; } minmax($inleg); get_the_result($inhead,$inleg); ?> 

you can use goto:

location: //... goto location; 

in case, need check whether functions exist not try declare them twice using function_exists.

while possible, recommend should rewrite code, approach unfeasible.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -