2

I have a sorted array in descending order such as with values 100 , 98, 96, 90 .... and I am using foreach() loop to iterate over the array and use if condition with limit 3 such as `

foreach($array as $arr){
if(loop_counter<3)
{ 
 echo 'something'; 
}}

to get top 3 positions. but the problem is that if there exist two same values such as 100 , 98, 98, 96, 90 . . then limits should increase from 3 to 4 so that on position 2 there exist two values 98, 98 and position 3 contain value 90 instead of 2nd 98. thanks in advance

8
  • 1
    array_unique Commented Feb 24, 2020 at 10:39
  • do you need both (duplicated) members? Commented Feb 24, 2020 at 10:39
  • @AbdullaNilam, does that dupe take into account the possibilities of duplicate values in the data? Commented Feb 24, 2020 at 10:42
  • @NigelRen check the second link on closed question. Commented Feb 24, 2020 at 10:45
  • Yes I need both duplicate number on one position such as if in exam 2 student have same marks they stand against one position. Commented Feb 24, 2020 at 10:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.