开发者

Printing a particular text in 2-D array using foreach loop only

given array is

$info=array("sanjay"=>array("male",20),
            "ravi"=>array("male",20),
            "rahul;"=>array("male",26),
            "tina"=>array("male",21),
            "sanjna"=>array("female",60开发者_JS百科)
            );

output should looks like this--

Name is: Sanjay Sex is: male and Age is: 20
Name is: ravi Sex is: male and Age is: 20
Name is: rahul Sex is: male and Age is: 26
Name is: tina y Sex is: female and Age is: 21
Name is: Sanjna Sex is: female and Age is: 60


Using a foreach loop would be optimal in this case:

foreach($info as $name => $more_info)
{
   printf("Name is: %s Sex is: %s and Age is: %d<br />", $name, $more_info[0], $more_info[1]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜