php7.2.2的函数 - 爱问答

(爱问答)

php7.2.2的函数

php7.2.2相对于低版本的做了哪些变化?除了mysql_connect改成了mysqli_connect,是只改了这一个函数吗?还有别的吗?

<?php $b = array(); each($b); // Deprecated: The each() function is deprecated. This message will be suppressed on further calls<?php count(''); // Warning: count(): Parameter must be an array or an object that implements Countable

非常简单的两个原生态函数,  可能在5.2,  5.6, 7.0时使用都不会有问题,  但php7.2是会严格报异常的. 

解决这两个函数, 需要重新定义函数. 如下. 

<?php echo fun_adm_count(''); function fun_adm_count($array_or_countable,$mode = COUNT_NORMAL){ if(is_array($array_or_countable) || is_object($array_or_countable)){ return count($array_or_countable, $mode); }else{ return 0; } }

本函数出自qadmin,  目的是参数进入时, 先判断是数组或者对象再使用count, 其它的全部返回0. 

 

<?php echo '<pre>'; $fruit = array(1,'a' => array('bbb'=>'ccc'), 'b' => 'banana', 'c' => 'cranberry'); while(list($key, $val) = fun_adm_each($fruit)){ echo "$key => $val "; } function fun_adm_each(&$array){ $result = array(); $key = key($array); if(!is_null($key)){ $val = $array[$key]; $result[1] = $val; $result['value'] = $val; $result[0] = $key; $result['key'] = $key; next($array); } return $result; }

此函数用人工方式操作了数据, 先取出key值, 再读取val值, 再next将指针前移一步. 返回数组格式.  

-------------------------

<?php $newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);'); echo "New anonymous function: $newfunc "; echo $newfunc(2, M_E) . " "; // outputs // New anonymous function: lambda_1 // ln(2) + ln(2.718281828459) = 1.6931471805599 // Warning This function has been DEPRECATED as of php 7.2.0. Relying on this function is highly discouraged.

create_function函数也过时了.  

解决方法是用闭包.  如:

<?php $fun = function ($str ){echo $str} $fun('Yuan');


相关标签:php

下一篇:mastercams2017图形怎么倒过来了

上一篇:易语言取每个进程读写的磁盘数据

热门标签:
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图片查看器怎么没有了?