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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:45:01+00:00 2026-06-18T12:45:01+00:00

Completely new to PHP I need to sort an array that was read in

  • 0

Completely new to PHP

I need to sort an array that was read in from a text file, line by line

$data = fgets($fileHandle);

Each $data contains 3 fields, which where exploded with

$otherData = explode(',',$data)

I need to sort the entire array ($data), by the first item in explode so it would be otherData[0];

from smallest to biggest, the firs item in explode is a number

how do i do this?

some research on google hasn’t gotten me very far, any help is appreciated

  • 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-18T12:45:02+00:00Added an answer on June 18, 2026 at 12:45 pm

    you can take the column you want to sort as the key of the array. then sort it with ksort

    $data = array();
    while($dataLine = fgets($fileHandle))
    {
        list($item1, $item2, $item3) = explode(',', $dataLine, 3);
        $data[$item1] = $item3;
    }
    ksort($data);
    print_r($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new with IFC files. For my company I need to read IFC
Disclaimer: completely new to Python from a PHP background Ok I'm using Python on
I'm new to PHP and am not sure how to proceed. The array that
I have a php file that contains an array $myArray . <?php $myArray =
I'm completely new to php. i need to play a video in vlc using
I am new to using prepared statements in mysql with php. I need some
Goodmorning everybody! I'm not completely new to PHP as in self but still kinda
I am trying to create some sort of new filesystem for a PHP cache-serving
I'm trying to read something from within HTML tags and I'm completely stupid when
I am developing an app for android where I need some data from a

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.