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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:36:22+00:00 2026-06-08T21:36:22+00:00

I need help working with arrays. I have an array of data from a

  • 0

I need help working with arrays. I have an array of data from a MySQL query. After printing it in a for loop, I get the following array_flip:

    Array ( 

   [Duru 60] => 0 
   [Maxwell 50] => 1 
   [Fashanu 70] => 2 
   [Nwankwo 80] => 3 
   [Obi 0] => 4 

   ) 

The array value is a combination of 2 fields name and total score. What I want to achieve is an array like so:

   Array (

   [Duru 60] => 60 
   [Maxwell 50] => 50 
   [Fashanu 70] => 70 
   [Nwankwo 80] => 80 
   [Obi 0] => 0 

   )

What I want to achieve is to change the default array numeric keys (0,1,2,3,4) to total score obtained from the query.

Here is the code that gave the first array block:

PHP code begins

    $dataA = array();

    foreach($data as $key => $val){

$dataC = $val['lastname']." ".$val['total'];
array_push($dataA,($dataC));

     }
     $dataD = (array_flip($dataA));

     print_r($dataD);
  • 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-08T21:36:24+00:00Added an answer on June 8, 2026 at 9:36 pm
    $dataA = array();
    foreach($data as $key => $val){
        $dataK = $val['lastname']." ".$val['total'];
        $dataV = $val['total'];
        $dataA[$dataK] = $dataV;
    }
    print_r($dataA);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an array of data, from which I can loop through specific
I am working with an array and need some help. I would like to
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
I'm working on a web application and need some help with a query. I'm
I need your help to translate a query into pyes. This query is working
I have constructed a array that gets the information from checkboxes. This is working
I'm new to working with arrays so I need some help. With getting just
I need help working with very big numbers. According to Windows calc, the exponent
I need help getting CommonJS working on Java 7 and Rhino 1.7R3. Rhino 1.7R3
All i need help in downloading a file through headers its working fine but

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.