## 标题 ## 你好这个php任务我想编写一个代码来制作出类似的 已经有了解决方案:D 但我想要更多:D:D:D
<?php
$data = array(
array(
'name'=>'Mark',
'job'=>'engineer',
'age'=>25,
'hobbies' => array('drawing','swimming','reading'),
'skills' => array('coding','fasting learning','teaching')
),
array(
'name'=>'Joe',
'job'=>'designer',
'age'=>19,
'skills'=>array('fast learning')
) ,
array(
'name'=>'sara',
'age'=>25,
'city'=>'NY'
),
array(
'name'=>'sam',
'job'=>'accountant',
'age'=>25,
'city'=>'london'
),
array(
'name'=>'Esraa',
'job'=>'Designer',
'age'=>23,
'city'=>'cairo',
'hobbies' => array('writing','reading'),
'skills' => array('coding','teaching')
),
);
/** out put should be like this ==>
*
* there is [number] of users from [city]
* ------------------------------------------
* name : sara
* age : 25
* city : Ny
* ------------------------------------------
* name : sam
* age : 25
* city : london
* job : accountant
* ------------------------------------------
* name : Esraa
* age : 23
* city : cairo
* job : Designer
* skills:
* -coding
* -teaching
* hobbies:
* -writing
* -reading
* ----------------------------------------------
* invalid data
* ------------
*
*
*/
؟>
答案 0 :(得分:1)
foreach($data as $key => $value){
if($value["city"] != ""){
if($count[$value["city"]] == ""){ $count[$value["city"]] = 1; }
else{ $count[$value["city"]]++; }
}
}
foreach($count as $key => $value){
echo "There are ".$value." users from ".$key."<br>";
}
echo "<br><br>";
foreach($data as $key => $value){
foreach($value as $key => $value){
if(($value != "")&&($key != "hobbies")&&($key != "skills")){
echo $key." : ".$value."<br>";
}
if(($key == "hobbies")||($key == "skills")){
echo $key.":<br>";
foreach($value as $kk => $vv){
if($vv != ""){
echo "-".$vv."<br>";
}
}
}
}
echo "<hr>";
}