Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array 1

Status
Not open for further replies.

iranor

Programmer
Joined
Jun 17, 2004
Messages
174
Location
CA
I have a mysql query that select numbers from a table.

With these numbers , I do an array.

How can I multiply these numbers and add the result in a variable?
 
You've fetched numbers from MySQL and stored them in an array.

What is it you wish to do with the numbers in the array?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I want to select all numbers from a certain field , make an array , then multiply all the numbers and return the result.

I've done the array , now I just need to know how to multiply and return result from the array
 
Since you are looping through the result set, simply multiply as you go. Am I missing something? If you loop through the result set and store it in an array, you will have to loop through the array again - seem likes unneccessary replication to me.

Let me know if I am missing something.
 
I would set some variable to 1, then loop through the array, multiplying the variable by every element in the array.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
let say I do :

$total_used = array('10','10','10');

How can I multiply the above numbers so the result here would give 1000 ?


 
Again.

Set a variable to 1. Loop through the array and multiply the variable by each element of the array.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
still don't understand... could you give me an example please
 
$total_used = array('10','10','10');

Let say it's my array. How would you multiply these and return the result?

I'm not very good in using arrays
 
Again, what part of my answer do you not understand how to do?

Assigning a value to a variable?
Looping through the elements of an array?
Performing multiplication?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks , I found.

<?
$total_used = array('10','10','10');
$result = 1;
foreach($total_used as $number){
$result = $number * $result;
}
echo "$result";
?>
 
That's exactly what I described.



I notice you used the verb "found", not "developed" or "wrote" or "created".

I strongly recommend that you take the time to get familiar with the basics of data-structures and manipulating them.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Well , i know basics... I'm doing an online game for the phpbb forum now ;)
 
That may be. But I see in your question evidence of substantial gaps in your knowledge of data-structure manipulation.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top