dongyi6269 2014-03-24 12:38
浏览 60

未使用的变量警告(编辑器)array_walk

Following code generates an editor warning for not using $key in the code. Any idea how to avoid this warning? Is there any similar check done by the PHP parses too?

array_walk($services, function(&$value, $key) {
    $value = str_replace('xxx', '', $value);
});
  • 写回答

2条回答 默认 最新

  • duanluan2047 2014-03-24 12:39
    关注

    From the manual documentation for array_walk:

    Typically, callback takes on two parameters. The array parameter's value being the first, and the key/index second.

    You can simply omit the $key as it isn't being used inside the callback function.

    array_walk($services, function(&$value) {
        $value = str_replace('xxx', '', $value);
    });
    

    It's important to note that what you have is perfectly valid PHP code. Just enable error reporting (if you haven't already) and fix any errors the PHP parser throws. There's no reason to change it just because your IDE complains so. In this particular case, it doesn't matter though.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分