我正在使用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
謝謝你的建議。我編輯了我的答案。 –