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 |
How is csrf token generated?
Why print_r is used in php?
What does PHP stand for?
What are different types of runtime errors in php?
Can php variables have numbers?
How do you identify independent and dependent variables in research?
Will php die?
<?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. -->
Is json a string php?
How to call a php function from html button?
What is substr() in php? And how it is used?
Which function(s) in PHP computes the difference of arrays?