douhe5092 2011-12-27 16:18
浏览 66
已采纳

在$ _POST中用NULL替换空值

I'm trying to replace empty field values with NULL, but can't seem to figure out how to do it. I've tried array_map, array_filter, and array_walk, but to no avail. Example:

function replaceWithNull($var)
{
    if (empty($var) || $var == ' ') {
        $var = "NULL";
    }
}

array_walk($_POST, "replaceWithNull");

Instead, it remains empty/blank. What am I missing?

  • 写回答

3条回答 默认 最新

  • dongwenyou4298 2011-12-27 16:21
    关注

    You have to use references for argument passing in order to alter the elements in the array:

    function replaceWithNull(&$var)
    {
        ...
    }
    

    Otherwise you will be changing only a copy of the variable.

    Read about it here: http://www.php.net/manual/en/functions.arguments.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Qt中实现子线程和管理线程类之间实时通信
  • ¥15 cacls 命令如何解除锁定文件夹?
  • ¥50 C++使用TWAIN协议如何实现A3幅面扫描仪扫描A4横向
  • ¥15 如何在sql server里完成筛选
  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?