2013-07-23 157 views
-1

的问题是要改变全局变量的值,每次子叫,我怎么能做到这一点如何让静态变量初始化为全局变量

  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(); 

我曾经尝试这样做太

  function sub() 
      { 
      global $present; 
      global $max; 
      global $min; 
     if($present==$min) 
     { 
    $present=$max; 
      } 
      $present--; 

      return $present; 
       } 

       sub();//it works only once 
       sub(); 
       sub(); 

,请提供给我的解决方案,这样我可以改变全局变量每次调用函数的值.......谢谢

子的主要功能是检索值FRM数据基地,但仍然SRC相同,无论多少次,我呼叫改变功能,请帮我出

  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 * from showcase where 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> 
+0

你有没有听说过[indentation](http://en.wikipedia.org/wiki/Indentation)? –

+0

没有让你对不起? – user2558479

+0

@Maerlyn我已经把实际使用...现在除了我的qustn请现在看到 – user2558479

回答

1

此代码的工作对我来说:

<?php 

$x = 5; 

function sub() { 
    global $x; 

    --$x; 
} 

sub(); var_dump($x); 
sub(); var_dump($x); 
sub(); var_dump($x); 
sub(); var_dump($x); 

输出为4,3,2,1。请参阅为自己:http://3v4l.org/Tic1v

+0

我已经把代码的使用,现在请解决我的问题 – user2558479

+0

你是可怕的混合客户端和服务器端代码。这不能简单地修复。 – Maerlyn