我正在使用Codeigniter 3,并从API获取数据。 在我将原始json数据通过$myArray = json_decode($theBody, true);之后,API返回以下内容
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 "
";
echo var_dump($this->session->flashdata('message'));
echo "
";我得到了预期的输出(与上面相同):
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"]
任何指针表示赞赏。