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

  • Home
  • SEARCH
  • 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 8394865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:09:45+00:00 2026-06-09T20:09:45+00:00

I have an object with 3 properties. I’d like to input a number 1,2,

  • 0

I have an object with 3 properties. I’d like to input a number 1,2, or 3 (0,1,or 2 is fine too) and sort the object in ascending numerical order based on one its property values.

Here’s what my object looks like:

var_dump($obj);

array(3) { 
    [0]=> object(stdClass)#25 (92) { 
        ["file_id"]=> string(1) "6" 
        ["name"]=> string(1) "1st item" 
    } 
    [1]=> object(stdClass)#26 (92) { 
        ["file_id"]=> string(1) "7"    
        ["name"]=> "2nd item"
    } 
    [2]=> object(stdClass)#27 (92) { 
        ["file_id"]=> string(1) "8" 
        ["name"]=> "3rd item"
    }
}

If I input 1, then the output would look like this:

file_id    name
 6      1st item
 7      2nd item
 8      3rd item

If I input 2, then the output would be:

7  2nd item
8  3rd item
6  1st item

If I input 3, then the output would be:

8  3rd item
6  1st item
7  2nd item

This question is nearly identical to one I asked earlier on Stackoverflow , the sole exception being that I need to sort() on the index positions of the file_id values and not on the file_id values themselves. I.e., I need to sort on 1,2,3 and not 6,7,8.

If you are particularly excited about this question (yes I realize this is unlikely), i’d be curious to know what the numbers 25 and 92 stand for in the output: object(stdClass)#25 (92).

  • 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-09T20:09:46+00:00Added an answer on June 9, 2026 at 8:09 pm

    As I understand your question after sorting an array by some property you want to rotate the array so that e.g. the array (1,2,3,4) becomes (3,4,1,2).
    I’m using string literals as array members in this example, switching to objects is trivial.

    <?php
    $sortedData = array('A', 'B', 'C', 'D', 'E'); // getting an array like this has been solved by the answers to your previous question
    $foo = rotate($sortedData, 2);
    var_dump($foo);
    
    
    function rotate($source, $n) {
        // could use some pre-checks...
        return array_merge(
            array_slice($source, $n, NULL, true),
            array_slice($source, 0, $n, true)
        );
    }
    

    prints

    array(5) {
      [0]=>
      string(1) "C"
      [1]=>
      string(1) "D"
      [2]=>
      string(1) "E"
      [3]=>
      string(1) "A"
      [4]=>
      string(1) "B"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have some sort of lazy initialied object properties in javascript
I have an object and one of its properties is object.type when I return
i have object like this: some_object this object has like 1000 properties. i would
Let's assume I have an array of object properties I'd like to access: $properties
Problem is: Chrome automatically sorts properties of object. If I have an object like:
With javascript, you can have one object inherit properties from another, so that if
I have an object that has properties of another object and one called DataValue
I have a object with properties that are expensive to compute, so they are
I have an object that has properties, but when I try to access them,
I have an object that gets properties added in this sequence. Home School living

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.