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 6243365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:07:38+00:00 2026-05-24T12:07:38+00:00

At first – yes, I’ve tried to find my problem here, but can’t make

  • 0

At first – yes, I’ve tried to find my problem here, but can’t make it.

I have a problem with array sorting. I want to use custom array sorting to sort some data taken from DB.

For example, I have array

values: [ 0, 0, 0, 0, 14830, 78426, 0, 0, 0, 0, 0, 0, 6024, 1144, 4438, 19282 ]

And I need to get last 4 (sometimes 3 or 2, so it would be custom) results on the first place in the same order as they are now. And the result should be like:

values: [ 6024, 1144, 4438, 19282, 14830, 78426, 0, 0, 0, 0, 0, 0,]

How can I do that?

I make this array with

while($row=mysql_fetch_array($re))
{
$dates = $row['mon'];

 while ($current_month != $dates) {
  $current_month = $current_month + 1;
  if($current_month == 13)
  $current_month = 1;
  $data[] = 0;
 }
 $data[] = intval($row['type']);
 $current_month = $dates+1;
}

I take months number as $current_month and using it puts my data in right places. When month have no results it adds 0 in that place.
The results should be just 6 and when there’s no passing through the years it makes array right, but sometimes it goes wrong like this, so I want to make proper array using custom sorting like I mantioned at first.

So I want to sort this array and with array_slice cut it to 6.

Thanks for help.

  • 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-05-24T12:07:40+00:00Added an answer on May 24, 2026 at 12:07 pm
    $desired_length = 4;
    $arr = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14);
    $length = count($arr);
    $array = array_slice($arr, $length-$desired_length, $desired_length) + array_slice($arr,0,$length-$desired_length);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First I want to thank you guys here, because your posts have gotten me
First of all: I really tried to find a matching answer for this, but
First time posting here, will try to be succinct. This is a classic 'can't
First of all, I know how to build a Java application. But I have
First off...here's the problem... Give an example of a directed graph G = (V,
First of all, yes I have read the other articles deal (I like your
first I used onDestroy() method as below to make something when my app is
First, I have a dbcontext factory which is defined public class DatabaseFactory : Disposable,
First I will ask users How many names you want to enter?. Once they
First of all i have to those categoryIDs 1-whos parentcategoryID only appears one 2-ParentCategoryID

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.