php循环

Jun 13, 2016 am 10:52 AM
array echo year

php循环求助

sql查询结果为
year mon
2012 5
2012 4
2012 3
2011 12
2011 11
...

怎么写php循环让它这样输出
2012 
5
4
3
2011
12
11
10
...

------解决方案--------------------
$array=array();

foreach(){
if(isset($array['year'])){
$array['year'][]=$result['mon'];
}else{
$array['year']=$result['year'];
$array['year'][]=$result['mon'];
}

foreach $array print_r;

大概这意思...
------解决方案--------------------
$last = '';
while($r = mysql_fetch_assoc($rs)) {
if($r['year'] != $last) {
echo $r['year'] . '
';
$last = $r['year'];
}
echo $r['mon'] . '
';
}
------解决方案--------------------

探讨

$last = '';
while($r = mysql_fetch_assoc($rs)) {
if($r['year'] != $last) {
echo $r['year'] . '
';
$last = $r['year'];
}
echo $r['mon'] . '
';
}
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

Go language development essentials: 5 popular framework recommendations

Sort array using Array.Sort function in C# Sort array using Array.Sort function in C# Nov 18, 2023 am 10:37 AM

Sort array using Array.Sort function in C#

Implementing distributed task scheduling using Golang's web framework Echo framework Implementing distributed task scheduling using Golang's web framework Echo framework Jun 24, 2023 am 11:49 AM

Implementing distributed task scheduling using Golang's web framework Echo framework

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher?

Detailed explanation of the role and usage of the echo keyword in PHP Detailed explanation of the role and usage of the echo keyword in PHP Jun 28, 2023 pm 08:12 PM

Detailed explanation of the role and usage of the echo keyword in PHP

Simple and clear method to use PHP array_merge_recursive() function Simple and clear method to use PHP array_merge_recursive() function Jun 27, 2023 pm 01:48 PM

Simple and clear method to use PHP array_merge_recursive() function

Explore the Go language framework: 5 choices not to be missed! Explore the Go language framework: 5 choices not to be missed! Feb 19, 2024 pm 02:29 PM

Explore the Go language framework: 5 choices not to be missed!

See all articles