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
What is session and why do we use it?
Write a program in php to find the occurrence of a word in a string?
How to remove an empty directory?
What is in a cookie?
Which of the delimiter is ASP style?
Do you know what is the difference between the include() and require() functions?
Which framework is best for php?
What are default session time and path?
What is the importance of "action" attribute in a html form?
How many types of php are there?
What are the rules for naming a php variable?
What is a query in php?
What is php namespace?
How to include a file to a PHP page?
What is strcmp () in php?