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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:39:41+00:00 2026-06-02T06:39:41+00:00

I have created an array of data, from which I can loop through specific

  • 0

I have created an array of data, from which I can loop through specific fields and echo these values out, but what I need to do is add these values to a new array, ultimately allowing me to find the average of the values in the new array. As i’ve said, I can echo out the data, and I think I’ve figured how to get the average, if only I can create the new array! Any help would be greatly appreciated as I just can’t find the answer anywhere, and I’m running low on talent!

My table contains approx 25 fields, im pulling out a number of rows based on a session variable. In the instance im working on, I need to take just the values from 1 column in the table, and add these to an array. The code below will loop through the values, and echo them out, 1 at a time:-

while ($cdarray=mysql_fetch_array($calldata))   {
echo $cdarray['score_total'];
}

This gives me 25555 which are the 4 values I would expect 25, 5, 5, 5

I’ve tried

while ($cdarray=mysql_fetch_array($calldata))   {
$cdts = $cdarray['score_total'];
$cdtsar = array($cdts);
}

Which results in $cdts being assigned a value of 5,

Any help greatly 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-02T06:39:45+00:00Added an answer on June 2, 2026 at 6:39 am

    This will get your data from the array, place it into a new one and calculates the average.

    $cdtsar = array();
    
    while ($cdarray=mysql_fetch_array($calldata))   {
     $cdtsar[] = $cdarray['score_total'];
    }
    
    $average = array_sum($cdtsar) / count($cdtsar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying the create a loop to extract data from an array created
I have created 4 buttons via Interface Builder. I have an array which has
Hi I have created a setDecorator() which is something like this: $timeSu->setDecorators(array('ViewHelper', 'Description', 'Errors',
In android, through xml parsing i have xml file values in tableview now which
In my application I have the array, which create in Main_View_Controller from json response
I have python code below that will loop through a table and print out
i have created Array of Linkbutton and when user click on link button it
I have created an array Man: public main blah blah{ man = man[10]; }
I have created an array in php that prints this Array ( [mark] =>
I have an array created with this code: var widthRange = new Array(); widthRange[46]

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.