How to solve array operations

Source: Internet
Author: User
The array operation Post Is Last edited by lazygc520 from 2013-06-2518: 14: 38 $ SQL & nbsp ;=& nbsp; "select & nbsp; * & nbsp; from & nbsp; table & nbsp; where & nbsp; cloumn & nbsp ;... array Operations
This post was last edited by lazygc520 at 18:14:38 $ SQL = "select * from table where cloumn ...";
$ Result = mysql_query ($ SQL );
$ Var = array ();
While ($ row = mysql_fetch_array ($ result, MYSQL_NUM ))
{
$ Var [] = $ row;
}

Foreach ($ var as $ v)
{
Foreach ($ v as $ key => $ value)
{
Echo $ value .' ';
}
}

The result is as follows:

4890 // value1;

1635
624 // value2;

4890 // value3;

How can I change the result:

4890

2249 // 1635 + 624;

4890

This method cannot be used for calculation. The result is incorrect:

Foreach ($ var as $ v)
{
Foreach ($ v as $ key => $ value)
{
$ Total + = $ v [$ value];
Echo $ total;
}
}

The result is as follows:

4890

7139 // 4890 + 2249

12029 // 4890 + 2249 + 4890

Find a solution.
Share:
------ Solution --------------------
$ Var is not the array. Is it wrong?
------ Solution --------------------
What does this mean?
$ar = array(
  array( 1635 ),
  array( 624 ),
);

$res = array();
foreach($ar as $item) {
  foreach($item as $v) $res[] = $v;
}
echo array_sum($res) . '//' . join('+', $res);
2259 // 1635 + 624

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.