doupang1917 2010-07-05 19:48
浏览 18
已采纳

PHP函数从数组构建查询字符串 - 而不是http构建查询

Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little problem.

It "handly" turns boolean values into ones and zeros for me. I am building a little PHP wrapper for the Stack Overflow api and parsing an option array and then sending this onto the api breaks things..(doesn't like 1 for true).

What I would like is a simple function to turn a single dimensional array into a query string but turning true/false into string values of true/false.

Anyone know of anything that can do this before I start re-inventing the wheel

  • 写回答

5条回答 默认 最新

  • douke6424 2010-07-05 19:53
    关注

    I don't know of anything offhand. What I'd recommend is first iterating through the array and covert booleans to strings, then call http_build_query

    E.g.

    foreach($options_array as $key=>$value) :
        if(is_bool($value) ){
            $options_array[$key] = ($value) ? 'true' : 'false';
        }
    endforeach;
    $options_string=http_build_query($options_array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题