How can I check if a value is already in an array?
Answers were Sorted based on User's Feedback
Answer / mohammed khalid khan
The first answer is not complete.
&
The second answer is correct.
<?php
$values = array("banana","apple","pear","banana");
if (in_array("pear",$values))
{
echo "Got pear";
}
?>
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / 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 |
Answer / deep
The above answer is correct. I will just add a complete
example.
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os))
{
echo "Got Irix";
}
if (in_array("mac", $os))
{
echo "Got mac";
}
?>
Is This Answer Correct ? | 7 Yes | 2 No |
What is super keyword in c++?
when ever the user logged in the database table the current registered date will be appeared
Which of the following represents the proper way to set a session variable? Answer: a. $_SESSION['foo'] = 'bar'; b. session_start(); c. session_set_save_handler ('myopen', 'myclose', 'myread', 'mywrite', 'mydelete', 'mygarbage'); d. $foo = $_SESSION['foo']; 2.When administering MySQL, you should make the data directory accessible via the operating system 3.which statement can be used to determine how the optimizer resolves a query
Does winrunner 8.0 or qtp 8.0 supports php
Write a program to upload a file in php?
we store and display scores of users in different games. In MySQL, records are stored as tuples (user-id, game-id, score). Now we need to support ranks of users, i.e., each user should be informed of his current rank in the community. The challenge is to come up with the best way to store the data in MySQL so that the requirements are efficiently met.
How to print \ in php. Only \ with out using . or *.
how we can use lamp.ie installatiion and basic workings.Is it similar to wamp in usage?
Explain the casts allowed in PHP?
How to convert one date format into another in php?
what is used for tmp table in oracle?
Write a program in php to check whether a number is prime or not?