A->b->c
might exist but c
might not exist. How do I check it?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
If
c
does not exist, its value will benull
(or, to be more precise, it will have no value). Note, however, that for this to work, bothA
andb
need to not benull
. Otherwise, PHP will throw an error (I think).I solved it by using the
children()
function and doing acount()
on it, ignoring an PHP error if there are no children by putting an @ before the count-call. This is stupid, but it works:I hate this...
The 3 ways I can confirm work in PHP 5.5.23 were using
isset()
count()
orempty()
Here is a script to show the results from each:
https://gist.github.com/mchelen/306f4f31f21c02cb0c24