Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:04:38+00:00 2026-06-01T03:04:38+00:00

I have a array with users sorted by score. I only want to output

  • 0

I have a array with users sorted by score.
I only want to output a specific users score (in the middle of the outputted list), and users before and after to make the list max length 10.

Like this

1.  A
2.  B
3.  C
--------- OUTPUT START
4.  D
5.  E
6.  F
7.  G
8.  H (ME)
9.  I
10. J
11. K
12. L
13. M
--------- OUTPUT END
14. N
15. O
16. P

Any ideas on how to do this?
Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:04:39+00:00Added an answer on June 1, 2026 at 3:04 am

    Try that:

    $my_rank;
    foreach ($scores as $key => $value) {
      if ($value == 'H') { // 'H' being your name.
        $my_rank = $key;
      }
    }
    $surroundings = array_slice($scores, max(0, $my_rank - 4), 10);
    

    It takes the id of your name in the array and slices the array from your rank-4 with size of 10. If your rank is less than 4, it takes 0 instead (it’s the max part).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of users that's sorted in descending order based on total_points.
I have this block of code: users = Array.new users << User.find(:all, :conditions =>
If I have an array of say, some ID's of users. How could i
I have an array of users who are friends. Let us call this array:
I have an array of items as follows in Javascript: var users = Array();
I have hardcoded array called users in a PHP function: protected static $users =
I have an array of strings: [users, torrents, comments] these strings are the names
I have an array of street names sorted alphabetically that I have gathered from
I have an array of users who are managers. However there are repeated Users.
I have a list of users (six to be exact) in a collection with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.