Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


How can I check if a value is already in an array?

Answers were Sorted based on User's Feedback



How can I check if a value is already in an array? ..

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

How can I check if a value is already in an array? ..

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

How can I check if a value is already in an array? ..

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

Post New Answer



More PHP Interview Questions

what are the basic steps to installation php4+mysql4+phpmyadmin on IIS web server?. Pls write the complete steps.

2 Answers  


How many types of array supported in php?

0 Answers  


Can we run php in apache tomcat?

0 Answers  


How to know user has read the email-php?

0 Answers  


Explain the difference between array_merge() and array_combine()?

0 Answers  






How do I repair phpmyadmin?

0 Answers  


How to set session.gc_maxlifetime properly?

0 Answers  


What is the difference between $message and $$message?

2 Answers  


Explain how can we execute a php script using command line?

0 Answers  


Are parent constructors called implicitly inside a class constructor?

0 Answers  


write a program to generate bill screen 1.1st page should get the number of products to be billed. 2.2nd page should display the number of rows according to the number of products given in the first page. 3.Each row should have a text box for a.product name b.quantity c.unit price d.item price = quantity x unit price This should be automatically calculated not to be entered by the user. 4.After entering the products calculate sales-tax for the total amount which 8.25%. 5.After entering these values you have to generate the bill in the next page with a unique number for the bill. can anyone solve this problem..i am in need to solve this problem..pls help me

1 Answers   Yahoo,


Tell me can you extend a final defined class?

0 Answers  






Categories