2017-03-06 129 views
0
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使用這個喜歡PHP的foreach得到的stripslashes()預計參數1

foreach ($jsondeduction as $val) { 
       $jsondeductionspayments = json_decode(stripslashes($val['deductionspayment']), true); 

但我得到的錯誤,我假設錯誤從這一行來: $jsondeductionspayments = json_decode(stripslashes($val['deductionspayment']), true);

我應該如何格式化該數據,以便stripslashes

+0

第一個問題是 - 爲什麼你甚至使用'stripslashes'? –

+0

刪除斜線以防有斜槓? – Giant

+0

錯誤本身說你應該傳遞字符串而不是數組(數組) –

回答

0

stripslashes

的stripslashes - 反引用一個引用

string stripslashes (string $str) 

的stripslashes當你發送一個數組$val['deductionspayment']這是不變量字符串需要字符串參數

0

試試這個:

foreach ($jsondeduction as $val) { 
       $jsondeductionspayments = stripslashes(json_decode($val['deductionspayment']), true); 
0

條紋對字符串起作用。你提供了一個數組$ val ['deductionspayment']。

string stripslashes (string $str);

0

錯誤是由於stripslashs陣列產生。

$jsondeduction_decode=json_decode($jsondeduction) 
$jsondeduction_stripslash=unstrip_array($jsondeduction_decode['deductionspayment']); 

    function unstrip_array($array){ 
     foreach($array as &$val){ 
      if(is_array($val)){ 
       $val = unstrip_array($val); 
      }else{ 
       $val = stripslashes($val); 
      } 
     } 
    return $array; 
    } 
相關問題