首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP foreach获取stripslashes()需要参数1

PHP foreach获取stripslashes()需要参数1
EN

Stack Overflow用户
提问于 2017-03-06 16:27:23
回答 4查看 484关注 0票数 0
代码语言:javascript
复制
array(1) {
  [0]=>
  array(11) {
    ["deductionspayment"]=>
    array(3) {
      [0]=>
      array(3) {
        ["amount"]=>
        string(4) "1.03"
        ["year"]=>
        string(4) "2017"
        ["month"]=>
        string(5) "March"
      }
      [1]=>
      array(3) {
        ["amount"]=>
        string(4) "1.03"
        ["year"]=>
        string(4) "2017"
        ["month"]=>
        string(5) "April"
      }
      [2]=>
      array(3) {
        ["amount"]=>
        string(4) "1.03"
        ["year"]=>
        string(4) "2017"
        ["month"]=>
        string(3) "May"
      }
    }
    ["deductionsname"]=>
    string(3) "SSS"
    ["deductionstart"]=>
    string(10) "2017-03-08"
    ["deductionsend"]=>
    string(10) "2017-03-14"
    ["deductionsamount"]=>
    string(4) "3.09"
    ["deductionsyears"]=>
    string(1) "3"
    ["deductionsdate"]=>
    string(10) "2017-03-18"
    ["deductionschedule"]=>
    string(1) "3"
    ["deductionstype"]=>
    string(1) "1"
    ["deductionsprincipalamount"]=>
    string(1) "3"
    ["deductionsinterest"]=>
    string(1) "3"
  }
}
<br />
<b>Warning</b>:  stripslashes() expects parameter 1 to be string, array given in 
<b>Warning</b>:  Invalid argument supplied for foreach() in 
{"error":false,"message":"Update Successful.!"}

这是我$jsondeduction的var_dump,我在foreach中使用它,如下所示

代码语言:javascript
复制
foreach ($jsondeduction as $val) {
                $jsondeductionspayments = json_decode(stripslashes($val['deductionspayment']), true);

但是我得到了错误,我假设错误来自这一行:$jsondeductionspayments = json_decode(stripslashes($val['deductionspayment']), true);

我应该如何格式化此数据以允许stripslashes

EN

回答 4

Stack Overflow用户

发布于 2017-03-06 16:35:21

stripslashes

-取消引用带引号的stripslashes字符串

代码语言:javascript
复制
string stripslashes ( string $str )

stripslashes在发送不是字符串变量的数组$val['deductionspayment']时需要字符串参数

票数 0
EN

Stack Overflow用户

发布于 2017-03-06 16:36:15

试试这个:

代码语言:javascript
复制
foreach ($jsondeduction as $val) {
                $jsondeductionspayments = stripslashes(json_decode($val['deductionspayment']), true);
票数 0
EN

Stack Overflow用户

发布于 2017-03-06 16:39:25

条纹斜杠在字符串上有效。你提供了一个数组$val‘’deductionspayment‘。

代码语言:javascript
复制
string stripslashes ( string $str );

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42620793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档