慕码人2172434
2017-08-27 14:04
<?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 ) ... ) */ ?>
PHP进阶篇
181839 学习 · 2577 问题
相似问题
回答 1
回答 1