In the actual test, when PHP reads the json array and uses simple if or array_key_exists to determine whether the object exists, an error will be reported. The following is the correct judgment method from Google search
In fact, the error is reported because I am not very proficient in PHP. Maybe the correct judgment method I think is not the most perfect solution or even wrong. This blog post is reserved for my own use. Error code:
<span>$structure</span> = <span>imap_fetchstructure</span>(<span>$connection</span>, <span>$id</span>,<span> FT_UID); </span><span>if</span> (<span>array_key_exists</span>('parts', <span>$structure</span><span>)) { }</span>
An error will appear Warning: array_key_exists() expects parameter 2 to be array, boolean Given
The correct solution is:
<span>if</span> (<span>is_array</span>(<span>$structure</span>) && <span>array_key_exists</span>('parts', <span>$structure</span>)) <br>{ <span>//</span><span>...magic stuff here <br>}</span>
And another way is to use isset to directly judge:
<span>if</span>(<span>isset</span>(<span>$structure</span>['parts'<span>])) { }<br></span>
// Therefore, it is necessary to return TURE
only if the variable exists and the value is not NULL
The above introduces the method for PHP to return json and PHP to determine whether a json object exists, including the content of PHP returning json. I hope it will be helpful to friends who are interested in PHP tutorials.