Search This Blog

check array index or key with user inputs in php

check_array_key.php :

<center>
<?php

$num1=array(1,2,3,4,5,6,7,8,9,10,'a'=>'A');
$key=@$_POST['key'];

if (array_key_exists($key, $num1))
{
echo 'array index/key :<b> '.$key.' </b> found<br>';
}
else
{
echo 'array index/key :<b> '.$key.' </b> not found<br>';
}

?>
==========================================================

check_array_index.php :

<center><b>here checks index is in array or not</b><br><br>
<form action="check_array_key.php" method="POST">
<input type="textbox" name="key">
<input type="submit" name="submit">
</form>

============================================================
input :

1) give the array index value in text box
2) click on button

ex :

$num1=array(1,2,3,4,5,6,7,8,9,10,'a'=>'A');

here "0-9" and "a" are  indexes

"1-10" and "A" are values

============================================================

output :

array index/key : not found

array index/key : 1 found

Share Links

Related Posts Plugin for WordPress, Blogger...