我正在使用Codeigniter 3并从API获取数据。该API返回下方后,我通过通过原点的JSON数据,$myArray = json_decode($theBody, true);
codeigniter数组json和flashdata
array(2) {
["status"]=>
string(7) "failure"
["message"]=>
array(2) {
["entry_name"]=>
string(61) "The entry_name field must be at least 8 characters in length."
["entry_body"]=>
string(61) "The entry_body field must be at least 8 characters in length."
}
}
我现在想通过flashdata来传递错误信息,以我的观点,我做如下:
// VIEW FILENAME: new.php
$this->session->set_flashdata('message', $myArray);
在我视图,当我运行此:
echo "<pre>";
echo var_dump($this->session->flashdata('message'));
echo "</pre>";
我得到预期的输出(与上述相同):
array(2) {
["status"]=>
string(7) "failure"
["message"]=>
array(2) {
["entry_name"]=>
string(61) "The entry_name field must be at least 8 characters in length."
["entry_body"]=>
string(61) "The entry_body field must be at least 8 characters in length."
}
}
但是,我怎样才能遍历数组?
我怎么可以参考["status"]
赞赏内容和["message"]
任何指针。
给你的答案增加一些有用的解释 – Vikrant
谢谢你的建议。我编辑了我的答案。 –