Php determines whether a json object exists, and php judges a json object
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.