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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:15:40+00:00 2026-06-09T01:15:40+00:00

In my program I send an SQL query to a table and it returns

  • 0

In my program I send an SQL query to a table and it returns a resource which I use the function mysql_fetch_array() on. The first argument is the results resource from the SQL query but if you leave the next argument out the default is to return an array which has both the associative index id and the numerical id.

This is useful to me because I’m using these results to create another query so need to have access to both the associative id and the numerical one since I need to iterate through this array which involves incrementing the number. However, I have removed the null values through a PHP function and now I am left with an discontinuous numerical entries. I understand that I can use the array_values() function to recalibrate my IDs but this eliminates my associative IDs from the array.

Is there a way to only recalibrate my numerical ID’s but not remove the associative ID?

e.g.

'id' = [0] = '0001'
'gender' = [1] = null
'religion' = [2] = 'jewish'

I removed the null values, i.e. gender:

'id' = [0] = '0001'
'religion' = [2] = 'jewish'

Now I want to renormalise the numerical indices to:

'id' = [0] = '0001'
'religion' = [1] = 'jewish'
  • 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-09T01:15:42+00:00Added an answer on June 9, 2026 at 1:15 am

    I don’t think there’s a built in function for this, however you can iterate trough the array to get the numerically indexed values:

    $data = array(
        'id'       => '0001',
        'gender'   => null,
        'religion' => 'jewish',
        0          => '0001',
        1          => null,
        2          => 'jewish',
    );
    
    $num_keys = array();
    foreach ($data as $k => $v) {
        if ($v === null) {
            unset($data[$k]);
            continue;
        }
        if (is_numeric($k)) {
            $num_keys[$k] = $v;
            unset($data[$k]);
        }
    }
    ksort($num_keys);
    $data = array_merge($data, array_values($num_keys));
    var_dump($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I creating a program which send newsletter with a background image. It works fine
I'm using the program to send data from database to the Excel file .
I'm trying to get a little program to send hex over RS232. From what
Okay, so I'm writing a test program to send a vector of objects from
I am using Ajax to send query to PHP server, which then run the
I wrote a program to send mails from GAE. It can be run in
I would like my Delphi program to send email message via Outlook which will
I use C# program and my database is in SQL server 2008. When user
I have an old program pushing some data from a Microsoft SQL server database
I have a program to send POST request to a server. I'm using cURL

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.