Is there any function to find repeated value in an array?
What is w2 standard



Is there any function to find repeated value in an array? What is w2 standard..

Answer / amitverma

Yes, there's a function for everything in PHP :)
To see the repeated values in an array you may use function
array_count_values($array);

This function will return you an array, consisting each
vaule's frequency associated with it.


##
#Following Code -

$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));

##
#Outputs -

Array
(
[1] => 2
[hello] => 2
[world] => 1
)

Is This Answer Correct ?    11 Yes 3 No

Post New Answer

More PHP Interview Questions

How is csrf token generated?

0 Answers  


Why print_r is used in php?

0 Answers  


What does PHP stand for?

7 Answers  


What are different types of runtime errors in php?

0 Answers  


Can php variables have numbers?

0 Answers  






How do you identify independent and dependent variables in research?

0 Answers  


Will php die?

0 Answers  


<?php include ("db.php"); $result = mysql_query("SELECT ques_id FROM questionbank order by ques_id limit 5 "); while($obj=mysql_fetch_array($result)) { $ad1[$obj['ques_id']]++;//Used an array and inserted the database query results into it. } $rand_keys=array_rand($ad1,1); //Did a random array function echo "First random id = ".$ad1[$rand_keys[0]]; echo "<br>Second random id = ".$ad1[$rand_keys[1]]; ?> <!--Its not working. Have any solution for this. -->

1 Answers  


Is json a string php?

0 Answers  


How to call a php function from html button?

0 Answers  


What is substr() in php? And how it is used?

0 Answers  


Which function(s) in PHP computes the difference of arrays?

0 Answers  


Categories