Home > Backend Development > PHP Tutorial > 小白编程求解答.该怎么解决

小白编程求解答.该怎么解决

WBOY
Release: 2016-06-13 12:21:58
Original
1007 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.

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


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


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


4.
<br />echo checkyear('2016');<br />function checkyear($year){<br />    if($year%4==0 && $year%100!=0 <br><font color='#FF8000'>------解决思路----------------------</font><br> $year%400==0){<br />        return 366;<br />    }else{<br />        return 365;<br />    }<br />}<br />
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