array in_array function - checks a value exists in an array or not
in-array-function-example-in-php.php
.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>in_array function - checks a value exists in an array or not</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="in_array function - checks a value exists in an array or not">
<meta name="keywords" content="php, example, code, array, function, in_array">
<meta name="description" content="in_array function - checks a value exists in an array or not">
<style>
h2, h3, h4{background:#bbb; color:#000087;}
h2{ padding:3px; margin:3px; font-size:18px;}
h3{ padding:2px; margin:2px; font-size:16px;}
h4{ padding:2px; margin:2px; font-size:14px;}
body{ background:#FFFFFb;}
</style>
</head>
<body>
<h2>in_array function - checks a value exists in an array or not</h2>
<pre>
<?php
/*
--------------------------------------------------------------
let us make an array and fill it up with some values
--------------------------------------------------------------
*/
$myArray = array("apple", "book", "cat", "zoo");
echo "<h4>Output of myArray</h4>";
print_r($myArray);
/*
--------------------------------------------------------------------------------------
we want to check whether book is exist in the array or not by using in_array function
--------------------------------------------------------------------------------------
*/
$isBookExist = in_array("book", $myArray);
echo "<h3>Output using in_array function</h3>";
print "$"."isBookExist = ".$isBookExist;
if($isBookExist)
{
echo "<h4>book is exists.</h4>";
}
else
{
echo "<h4>book is not exists in the array.</h4>";
}
/*
--------------------------------------------------------------------------------------
we want to check whether modon is exist in the array or not by using in_array function
--------------------------------------------------------------------------------------
*/
$isModonExist = in_array("modon", $myArray);
echo "<h3>Output using in_array function</h3>";
print "$"."isModonExist = ".$isModonExist;
if($isModonExist)
{
echo "<h4>modon is exists.</h4>";
}
else
{
echo "<h4>modon is not exists in the array.</h4>";
}
?>
</pre>
</body>
</html>

No comments:
Post a Comment
leave your comments here..