+ 2

I need to print repeated values if there's any in php

I have an array and it's sorted with arsort In this code it prints "It's 2" but i also want to print the duplicate value and i don't know how to print them https://code.sololearn.com/wQl29r14jnzI/?ref=app

28th Jan 2022, 10:15 PM
Eric Vazquez
4 Antworten
+ 3
You can try this print_r("It's 2" . " ". $greaterPro);
29th Jan 2022, 3:19 AM
Vinayak
Vinayak - avatar
+ 2
You can do as follows $max_value = reset($fPro); foreach($fPro as $key => $value) { if($value < $max_value) break; echo "It's $key<br>"; } The reset function sets the internal pointer of an array to the first element and returns that first element. Since the array is already sorted that will give you the maximum value to compare in the for each loop. Here's another version using array_filter: $max = reset($fPro); $farr = array_filter($fPro, function($e) use($max) { return $e == $max; }); print_r($e); or in short using arrow functions: $max = reset($fPro); $farr = array_filter($fPro , fn($e) => $e == $max); print_r($farr);
29th Jan 2022, 5:13 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
I want to print the [2] position and the [3] position but not in the same line
29th Jan 2022, 4:35 AM
Eric Vazquez