Home > Backend Development > PHP Tutorial > 小白编程求解答.

小白编程求解答.

WBOY
Release: 2016-06-23 13:32:37
Original
830 people have browsed it

1.声明一个数组装5个会员(每个会员含有会员id,姓名,年龄,性别,注册时间信息),再将这些数据以表格形式表现出来,如果年龄在18以内显示未成年,在18~30显示青年,30~60显示中年,60以上显示老年,并要统计不同年龄段的人数

2.利用for循环做九九乘法表

3.利用while循环将1~500之间的质数找出来-->array

4.$year是闰年输出366,否则输出365


回复讨论(解决方案)

作业?
1.

<?php$arr = array(    array('id'=>1,'name'=>'a','age'=>17,'addtime'=>date('Y-m-d')),    array('id'=>2,'name'=>'b','age'=>19,'addtime'=>date('Y-m-d')),    array('id'=>3,'name'=>'c','age'=>31,'addtime'=>date('Y-m-d')),    array('id'=>4,'name'=>'d','age'=>62,'addtime'=>date('Y-m-d')),    array('id'=>5,'name'=>'e','age'=>18,'addtime'=>date('Y-m-d')),);echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';echo '<table>';echo '<tr><td>id</td><td>name</td><td>age</td><td>addtime</td><td>年龄段</td></tr>';$agegroup = array();foreach($arr as $v){    $agetype = checkage($v['age']);    if(isset($agegroup[$agetype])){        $agegroup[$agetype]++;    }else{        $agegroup[$agetype] = 1;    }    echo '<tr>';    echo '<td>'.$v['id'].'</td>';    echo '<td>'.$v['name'].'</td>';    echo '<td>'.$v['age'].'</td>';    echo '<td>'.$v['addtime'].'</td>';    echo '<td>'.$agetype.'</td>';    echo '</tr>';}echo '</table>';echo '统计结果<br>';foreach($agegroup as $k=>$v){    echo $k.':'.$v.'<br>';}function checkage($age){    if($age<18){        return '未成年';    }elseif($age>=18 && $age<30){        return '青年';    }elseif($age>=30 && $age<60){        return '中年';    }else{        return '老年';    }}?>
Copy after login


2.
echo '<table>';for($i=1; $i<=9; $i++){    echo '<tr>';    for($j=1; $j<=9; $j++){        echo '<td>'.$i.'*'.$j.'='.($i*$j).'</td>';    }    echo '</tr>';}echo '</table>';
Copy after login


3.
<?php$i=2;$result = array();while($i<=500){    $j = 2;    $k = sqrt($i);    $flag = 1;    while($j<=$k){        if($i%$j==0){            $flag = 0;            break;        }        $j++;    }    if($flag==1){        array_push($result, $i);    }    $i++;}print_r($result);?>
Copy after login


4.
echo checkyear('2016');function checkyear($year){    if($year%4==0 && $year%100!=0 || $year%400==0){        return 366;    }else{        return 365;    }}
Copy after login

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