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 to count all the lines of code in a directory and sub folder?
How check variable is set or not in php?
What is var_dump?
How to retrieve the original query string?
How is csrf token generated?
What is trim codeigniter?
How to Pass JSON Data in a URL using CURL in PHP?
Can I learn laravel without php?
Name some of the constants in php and their purpose.
Write logic to print Floyd's triangle in PHP?
What is the difference between explode and split?
what is PDO?
What is form action php?
Can php variables have numbers?
What are the rules for naming a php variable?