php - how to make static variable initialize to global variable -


the problem want change value of global variable each time sub called ,how can possibly it

         function sub()              {            static $x=global $present;             static $y=global $max;             static $z=global $min;         if($x==$z)         {      $x=$y;              }             $x--;            return $x;                }              sub();              sub();               sub(); 

i have tried too

          function sub()              {             global $present;             global $max;             global $min;         if($present==$min)         {      $present=$max;              }             $present--;            return $present;                }                sub();//it works once               sub();               sub(); 

please provide me solution can change value of global variable each time function called.......thank you

the main function of sub retrieving value frm data base ,src remains same no matter how many times call change function please me out

         function sub()               { global $present; global $max; global $min;        if($present==$min)         { $present=$max;           }           else            --$present;          return $present;                  }                  <script>             function change()                   {                      alert("hello");                  var x=document.getelementbyid("show");        x.src='<?php             if($con==true)             {        $cmd="select * showcase item_no=".sub();            if($res=$con->query($cmd))               {       if($res->num_rows>0)             {           while($rw=$res->fetch_array())            {             echo "$rw[1]";                 }                  }      else       {      echo "no record found";         }          }         else   {        echo "query problem";       }}             ?>';               alert(x.src);                      }                   </script> 

this code works me:

<?php  $x = 5;  function sub() {     global $x;      --$x; }  sub(); var_dump($x); sub(); var_dump($x); sub(); var_dump($x); sub(); var_dump($x); 

output 4, 3, 2, 1. see yourself: http://3v4l.org/tic1v


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -