Source Code:
(back to article)
<?php // Check if a value is present in an array $fruits = ["apple", "banana", "orange"]; if (in_array("apple", $fruits)) { echo "Found!"; } else { echo "Not found."; } // Check for a value of a different data type $numbers = [1, 2, 3, 4]; if (in_array("1", $numbers, true)) { echo "Found!"; } else { echo "Not found."; } // Check for the presence of zero or an empty string $values = [0, "", "foo", "bar"]; if (in_array("0", $values)) { echo "Found!"; } else { echo "Not found."; }
Result:
Report an issue