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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:25:20+00:00 2026-06-17T08:25:20+00:00

I am returning JSON from a web service using PHP. I am able to

  • 0

I am returning JSON from a web service using PHP. I am able to get the JSON, decode it, and see the results. However, I need to be able to sort the array by a particular value. I currently have:

// JSON URL which should be requested
$json_url = 'https://*******/maincategories';

// Initializing curl
$ch = curl_init( $json_url );

// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
);

// Setting curl options
curl_setopt_array( $ch, $options );

// Getting results
$result =  curl_exec($ch); // Getting JSON result string

$data = json_decode($result);

ksort($data, "Total");

print_r($data);

The print_r($data); prints this:

Array ( [0] => stdClass Object ( [Goal] => 10000000 [Name] => Rental [Total] => 500000 ) [1] => stdClass Object ( [Goal] => 8000000 [Name] => National Sales [Total] => 750000 ) [2] => stdClass Object ( [Goal] => 120000000 [Name] => Vendor Leasing [Total] => 500000 ) )

I was attempting to use ksort and sort the array by ascending order via the Total key. How can I sort this array so that the object with the highest total is first, and the rest follow in ascending order?

  • 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-17T08:25:21+00:00Added an answer on June 17, 2026 at 8:25 am

    This should work for you:

    usort($data, function ($a, $b) {
        return $a->Total - $b->Total;
    });
    

    Note that if you want an associative array instead of objects from json_decode, then use json_decode(..., true)

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

Sidebar

Related Questions

I'm retuning a JSON object from a web service and using knockout 2.01 to
Ok, so first off here's the JSON that's returning from my web service. I'm
Using a non-JSON-enabled VB.Net web service (or really any web service in general), I've
I'm using Qjson to parse a json object that is returned from a web
We have a web application providing a service using a simple REST interface (GET/POST
I have a web service returning JSON, but now I'd like to modify it
I'm returning some JSON from the web server, but I am unable to reference
I'm having issues connecting to an ASP.Net web service using PHP. The web service
I have a web service that is returning JSON. When testing the program, either
I have a web service returning some Json stuff to my iPhone application and

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.