I have an array with filenames.
I want to check if the array have a file with extension ‘.txt’.
How can I do that?
in_array only checks for a specific value.
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.
Contrarily to other answers suggesting
array_filter, I don’t return something. I just check if it exists in the array. Besides, this implementation is more efficient thanarray_filterbecause it breaks out of the loop once it’s found something.