If I have an array:
[null, 'a', 'b', 'c']
I want to get the first non-null value from the array, in this case "a". How could I go about doing that nice and easily?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not sure about nice and easy. But a short approach might be:
Where
array_filterwill extract you the “truthy” values, thus skipping empty and false entries. Whilecurrentsimply gives you the first of those remaining entries.