Home > Backend Development > PHP Tutorial > 数组操作,该如何解决

数组操作,该如何解决

WBOY
Release: 2016-06-13 12:44:23
Original
896 people have browsed it

数组操作

本帖最后由 lazygc520 于 2013-06-25 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.'
';
    }
}

显示结果如下:

4890//value1;

1635
624 //value2;

4890//value3;

请问怎么改能让结果变成:

4890

2249//1635+624;

4890

不能用这个方式计算,结果不对:

foreach($var as $v)
{
    foreach($v as $key=>$value)
    {
        $total += $v[$value];
        echo $total;
    }
}

结果如下:

4890

7139//4890+2249

12029//4890+2249+4890

求解决方法。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template