How can I check if a value is already in an array?
Answer Posted / jude jeevanraj.p
If you wish to check whether a value is already stored in
an array or not, then use the in_array function.
This is useful when you don't want any duplicates in the
array and therefore only want to add a value if it's not
already there. The first argument is the string you are
testing for and the second is the array you are checking
against.
Here is an example of in_array in action:
<?php
$values = array("banana","apple","pear","banana");
$newvalue = "pear";
if (in_array
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
When use javascript vs php?
What is php and features of php?
Which of the data type is compound datatype supported by PHP?
Tell me what are the encryption techniques in php?
What is cookie and why do we use it?
Differences between get and post methods?
What's the difference between accessing a class method via -> and via ::?
Is php secure?
Tell me what is the default session time in php?
What is an operator in php?
How we get ip address of client, previous reference page etc?
How can we change the maximum size of the files to be uploaded?
How to increase the maximum execution time of a script in php?
What is polymorphism with example in php?
Do you know what is the differences between $a != $B and $a !== $B?