Find element in array | PHP - IPropgramX

Q. Define an array. Find the elements from the array that matches the given value using appropriate search function.


HTML File:

<html>
<head>
<meta http-equiv="pragma" content="no-cache">
</head>
<body bgcolor="gold">
<form action="ass2b2.php" method="post">

Enter Number :<br>
<input type="text" name='no'>
<br><br>
<input type="submit" name="SUBMIT">    <input type='reset' name='CANCLE'>
</form>
<body>
</html>


PHP Function:
NOTE: PHP function is saved as "ass2b2.php"


<?php
$no=$_POST['no'];
if(empty($no))
{
        echo "Enter all data::";
        echo "<br><a href='a2b2.html'>Back</a>";
}
else
{
        $arr=array(1,2,3,4,5,6,7,7,8,9,10);
        print_r($arr);
        echo "<br><br><br>";
        if(in_array($no,$arr))
                echo "$no occured in array";
        else
                echo "$no not occured in array";
}
?>

Output:



Post a Comment

0 Comments