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
How do I end a php session?
What is framework in php for beginners?
What is file upload?
What is curl php?
Can I write php code in html file?
Is php a web server?
What is php beginner?
In php, objects are they passed by value or by reference?
How do I stop a php script?
How to write in a file in php?
What is the use of php and mysql?
What is the difference between null and empty?
What does trim () do in javascript?
Do you know what is the function mysql_pconnect() usefull for?
Difference between array_combine and array_merge?