drq22639 2015-07-27 09:51
浏览 25
已采纳

编程,使用全局变量的逻辑

lets say i have a function add().

function add(){
 if (a)
  return true;
 if (b)
  return true;
 if (c)
  insert into table. 
  return true;
 }

now i call this function add() and i want to increment my counter only if there is insert execution like condition C. I also don't want to change the return value which is true. Now my question is how can i find out if section C is executed? I thought i can use a global variable in condition c like below

if (c)
{
 insert into table. 
 $added = true;
 return true;
}

and then i check

if(isset($added && $added==true))
$count++;

but i would like to know if there is any parameter i can add or some other approach i can use?

  • 写回答

2条回答 默认 最新

  • doumaikuang4202 2015-07-27 09:54
    关注

    Add an if around your insert, and add a counter as a parameter:

    $count = 0;
    function add(&$count){
     if (a)
      return true;
     if (b)
      return true;
     if (c)
      if(insert into table){ //Queries return a boolean
        $count++;
      } 
      return true;
    }
    
    add($count); //If insertion was succesful it added 1 to counter.
    echo $count; //Returns either 1 or 0 depending on insert statement.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧