PHP method for determining whether a JSON object exists (recommended), phpjson
In the actual test, when php reads a json array, if or array_key_exists is used to determine whether an object exists, an error is returned. The following is a correct method for google searching.
In fact, when an error is reported, I am not very familiar with php, so I may think that the correct judgment method is not the perfect solution or even the wrong one. This blog post is for your own use.
Error code:
$ Structure = imap_fetchstructure ($ connection, $ id, FT_UID); if (array_key_exists ('parts', $ structure )){}
The following error occurs: Warning: array_key_exists () expects parameter 2 to be array, boolean given
The correct solution is:
If (is_array ($ structure) & array_key_exists ('parts', $ structure) {//... magic stuff here}
Another method is to use isset for direct judgment:
If (isset ($ structure ['parts']) {}// this function is used to test whether the variable has been configured. If the variable already exists, true is returned. Otherwise, false is returned. // If the variable exists and the value is not NULL, true is returned.
The above section describes how to use PHP to determine whether a JSON object exists (recommended). I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!