为了账号安全,请及时绑定邮箱和手机立即绑定

PHP 新手請教老師們,如何不用IF判斷,顯示20~30,31~40,41~50 各年齡層的人數與性別以及平均薪資。(拜託~解救學生)

<?php
$employee = array(
		$Mary = array(
			"birthday" => "1976-02-14",
			"salary" => "44,000",
			"sex" => "female"),
		$Tom = array(
			"birthday" => "1996-08-22",
			"salary" => "32,000",
			"sex" => "male"),
		$Bill = array(
			"birthday" => "1985-04-01",
			"salary" => "40,000",
			"sex" => "male"),
		$Aaron = array(
			"birthday" => "1973-07-11",
			"salary" => "40,000",
			"sex" => "male"),
		$Diana = array(
			"birthday" => "1993-02-05",
			"salary" => "29,000",
			"sex" => "female"),
		$Deborah = array(
			"birthday" => "1989-12-05",
			"salary" => "35,000",
			"sex" => "female"),
		$Hedda = array(
			"birthday" => "1978-11-15",
			"salary" => "35,000",
			"sex" => "female"),
		$Jessica = array(
			"birthday" => "1982-05-22",
			"salary" => "35,000",
			"sex" => "female"),
		$Neil = array(
			"birthday" => "1970-01-07",
			"salary" => "55,000",
			"sex" => "male"),
		$Webb = array(
			"birthday" => "1977-11-01",
			"salary" => "43,000",
			"sex" => "male")
		);
		
      function birthday($birthday)
       { $age = strtotime($birthday); 
       if($age === false){
           return false; 
       } list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
       $now = strtotime("now"); 
       list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now)); 
       $age = $y2 - $y1; 
       if((int)($m2.$d2) < (int)($m1.$d1)) $age -= 1; 
       return $age; 
       } 
       echo "Mary age =" .birthday($Mary[birthday]). "<br>"; 
       echo "Tom age =" .birthday($Tom[birthday]). "<br>"; 
       echo "Bill age =" .birthday($Bill[birthday]). "<br>"; 
       echo "Aaron age =" .birthday($Aaron[birthday]). "<br>"; 
       echo "Diana age =" .birthday($Diana[birthday]). "<br>"; 
       echo "Deborah age =" .birthday($Deborah[birthday]). "<br>";
       echo "Hedda age =" .birthday($Hedda[birthday]). "<br>";
       echo "Jessica age =" .birthday($Jessica[birthday]). "<br>";
       echo "Neil age =" .birthday($Neil[birthday]). "<br>";
       echo "Webb age =" .birthday($Webb[birthday]). "<br>";
   /*    
寫一個 function 產出兩個結果

1.顯示20~30,31~40,41~50 各年齡層的人數與性別以及平均薪資
ex:
20~30:2,male:1,female:1,average salary:22,000
31~40:2,male:1,female:1,average salary:32,000
...

2.把第一題的結果組成二維陣列並用上方的print方式顯示出來
ex:
Array
(
    [20~30] => Array
        (
            [member] => 2
            [male] => 1
            [female] => 1
            [average salary] => 22,000
        )

    [31~40] => Array
        (
            [member] => 2
            [male] => 1
            [female] => 1
            [average salary] => 32,000
        )

    ...

)

*/
?>


正在回答

2 回答

为嘛,快照上去,按钮都失效了~—~

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

PHP 新手請教老師們,如何不用IF判斷,顯示20~30,31~40,41~50 各年齡層的人數與性別以及平均薪資。(拜託~解救學生)

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信