$value=array("Rabin","Reid","Cris","KVJ","John");
if(in_array("Cris",$value)){
echo "Cris is there inside the array";}
else{ echo "Cris is not there ";}
var_dump(PDO::getAvailableDrivers());
By using PDO::getAvailableDrivers()
we can get an array of available PDO drivers, so we can use in_array() to check the presence of SQLite inside the array and if-else to display appropriate message to user.
<?php
if (!in_array("sqlite",PDO::getAvailableDrivers(),TRUE))
{
throw new PDOException ("Cannot work without a proper database setting up");
}else{
echo "<font color='green'>Database setup is OK</font>";
}
?>
$a = array('abc','4.56', 4, 1.13);
if (in_array(4.56, $a, true)) {
echo "4.56 found with strict check";
}else{
echo "4.56 NOT found with strict check";
}
echo "<BR>";
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check";
}else{
echo "1.13 NOT found with strict check";
}
Output
4.56 NOT found with strict check
1.13 found with strict check
in_array(mixed $needle, array $haystack, bool $strict = false): bool
Function | Details |
---|---|
array_search() | Search for value inside Array. Returns the key if found, FALSE otherwise |
array_keys() | Array of keys for matching values, FALSE otherwise |
array_key_exists() | Search for key inside Array. True if found, FALSE otherwise |
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
smo1234 | 18-06-2012 |
nice site |