exception 'ErrorException' with message 'Illegal string offset 'tax''
这是我得到的致命错误
Log::error(print_r($pax_group , true));
Log::error(var_dump($pax_group));
if(isset($pax_group["otherdetail"]["tax"]["details"]["detail"][0]))
{
// I get the fatal error at the foreach line
foreach($pax_group["otherdetail"]["tax"]["details"]["detail"] as $one_tax)
{
$detail = new Otherdetail;
$detail->occ_paxs_id = $px->id;
$detail->code = $one_tax["code"];
$detail->amount = $one_tax["amt"];
$detail->B2Bamount = $one_tax["amt"];
$detail->save();
}
}
这是我在otherdetail里面的价值:<otherdetail>0</otherdetail>
当<otherdetail>0</otherdetail>
内没有[“tax”] [“details”] [“detail”] [0]时,任何人都知道我怎么可能通过isset?
[2017-09-27 14:57:28] production.ERROR: Array
(
[cost] => 1033.60
[retail] => 1157.632
[wholesale] => 1157.632
[othertotal] => 0.00
[otherdetail] => 0
)
[] []
[2017-09-27 14:57:28] production.ERROR: [] []
[2017-09-27 14:57:28] production.ERROR: exception 'ErrorException' with message 'Illegal string offset 'tax'' in /home/*****************:1525
更多xml:
<prices>
<total>
<cost>943.85</cost>
<wholesale>1021.6</wholesale>
<retail>1021.6</retail>
<othertotal>223.58</othertotal>
</total>
<paxgroup num="1">
<qty>2</qty>
<fromage>20</fromage>
<toage>120</toage>
<cost>471.93</cost>
<wholesale>510.80</wholesale>
<retail>510.80</retail>
<othertotal>111.79</othertotal>
<fare_type>PB</fare_type>
<components>
<AIR>
<cost>148.00</cost>
<retail>148</retail>
<wholesale>148</wholesale>
<othertotal>111.79</othertotal>
</AIR>
<HOT>
<cost>323.93</cost>
<retail>362.8016</retail>
<wholesale>362.8016</wholesale>
<othertotal>0.00</othertotal>
<otherdetail>0</otherdetail>
</HOT>
</components>
</paxgroup>
</prices>
JSON:
{"prices":{"total":{"cost":943.85,"wholesale":1021.6,"retail":1021.6,"othertotal":223.58},"paxgroup":[{"qty":"2","fromage":"20","toage":"120","cost":"471.93","wholesale":"510.80","retail":"510.80","othertotal":"111.79","fare_type":"PB","components":{"AIR":{"cost":"148.00","retail":148,"wholesale":148,"othertotal":"111.79"},"HOT":{"cost":"323.93","retail":362.8016,"wholesale":362.8016,"othertotal":"0.00","otherdetail":"0"}}}]}}
答案 0 :(得分:-1)
试试这个:
if(isset($pax_group['otherdetail']) && isset($pax_group['otherdetail']['tax']) && isset($pax_group['otherdetail']['tax']['details']) && isset($pax_group['otherdetail']['tax']['details']['detail'])){
//...
}