Checking for an Element in an Array in PHP


Use in_array() to check if a certain value exists in an array.

Source Code

$users = ['Alice', 'Bob', 'Charlie'];
if (in_array('Bob', $users)) {
    echo "Bob is in the users array.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments