php在function外面输出 - 爱问答

(爱问答)

php在function外面输出

<?php secondsToHour(6000);function secondsToHour($seconds){if(intval($seconds) < 60)$tt ="00:00:".sprintf("%02d",intval($seconds%60));if(intval($seconds) >=60){$h =sprintf("%02d",intval($seconds/60));$s =sprintf("%02d",intval($seconds%60));if($s == 60){$s = sprintf("%02d",0);++$h;}$t = "00";if($h == 60){$h = sprintf("%02d",0);++$t;}if($t){$t = sprintf("%02d",$t);}$tt= $h.":".$s;}if(intval($seconds)>=60*60){$t= sprintf("%02d",intval($seconds/3600));$h =sprintf("%02d",intval($seconds/60)-$t*60);$s =sprintf("%02d",intval($seconds%60));if($s == 60){$s = sprintf("%02d",0);++$h;}if($h == 60){$h = sprintf("%02d",0);++$t;}if($t){$t = sprintf("%02d",$t);}$tt= $t.":".$h.":".$s;}echo $seconds>0?$tt:'00:00:00';}?>


echo $seconds>0?$tt:'00:00:00';不在function里面输出

在外面function外面,让其等于$LabelArray['副标']

很不习惯php中的变量作用域,php中函数变量和全局是完全隔绝的,也就是无法相互访问。比如下面这样:复制代码代码如下:$test = 123; abc(); //这里什么都不输出,因为访问不到$test变量function abc(){    echo($test);}$test = 123;abc(); //这里什么都不输出,因为访问不到$test变量function abc(){    echo($test);}如果,你想在函数内部访问外部变量,你需要这样:复制代码代码如下:$test = 123; abc(); //输出123function abc(){    global $test;    echo($test);}$test = 123;abc(); //输出123function abc(){    global $test;    echo($test);}也就是说,你使用全局变量就可以在函数内调用外部定义过的变量

<?php  $x=fgets(STDIN)+0;  $result=array();  chk($x);  echo count($result)." ";  foreach ($result as $arr) echo "$x=".implode($arr,'+')." ";   function ss($x){  if ($x==2) return true;  $y=ceil(sqrt($x));  for ($i=2;$i<=$y;$i++)    if ($x%$i==0) return false;  return true;}function chk($x){  global $result;  $y=ceil($x/3);  for ($i=2;$i<=$y;$i++) if (ss($i))    for ($j=$i;$j<=$y;$j++) if (ss($j)){      $k=$x-$i-$j;      if (ss($k)) $result[]=array($i,$j,$k);    }}?>


相关标签:php

下一篇:求推荐计算机入门书籍

上一篇:用安卓eclipse设计出文件管理器,

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?