$hasVideo = $details['data']['topic']['has_video'];
For example such a piece of code, because do not know before the array ' data ', ' topic ' when there is value, need to determine the value of the assignment operation, how to easily judge to avoid the assignment times wrong.
If you only use the empty method, it seems to require such a layer of judgment in:
if(!empty($details)&&!empty($details['data'])&&!empty($details['data']['topic'])&&!empty($details['data']['topic']['has_video']))
Is there a simpler way? or write a public method of your own, and you can judge whether you can get the value at once.
Reply content:
$hasVideo = $details['data']['topic']['has_video'];
For example such a piece of code, because do not know before the array ' data ', ' topic ' when there is value, need to determine the value of the assignment operation, how to easily judge to avoid the assignment times wrong.
If you only use the empty method, it seems to require such a layer of judgment in:
if(!empty($details)&&!empty($details['data'])&&!empty($details['data']['topic'])&&!empty($details['data']['topic']['has_video']))
Is there a simpler way? or write a public method of your own, and you can judge whether you can get the value at once.
isset
It's OK to judge it by yourself.
$hasVideo = isset($details['data']['topic']['has_video']) ? $details['data']['topic']['has_video'] : $something_else;
may be oneself commit two, also was cheated by colleague. In fact, isset and empty can be judged.
I made a small test and found that I could not make an error.
array( test2=>array( test3=>array( test4=>123, ), ), ), ); var_dump(isset($test['test1']['test2']['test3']['test4']['test4']['test4']['test4'])); var_dump(!empty($test['test1']['test2']['test3']['test4']['test4']['test4']['test4']));?>
Use count or current to judge, multi-dimensional recursive detection.