使用getStuff()、getRelateStuff()、getRelatedStuffInStuff()获得数组数据
作者:admin 时间:2012-6-6 22:20:5 浏览:通过使用如下三个函数,获得数组array的数据。
getStuff();
getRelateStuff();
getRelatedStuffInStuff();
如下是代码:
function getStuff()
{
return array("It", "Works");
}
function Stuff()
{
$value = array(getStuff());
foreach ($value as $key => $value)
{
echo "$key $value <br />\n";
}
}
function getRelatedStuff()
{
return array("hello" => "world", "cake"=> "is a lie");
}
function RelatedStuff()
{
$value = array(getRelatedStuff());
foreach ($value as $key => $value)
{
echo "$key $value <br />\n";
}
}
//Related in Stuff
function getRelatedStuffInStuff()
{
$s1 = array("hello" => "world", "cake"=> "is a lie");
$s2 = array("apple" => "mac", "microsoft"=> "windows", "linus" => "linux");
$s3 = array("OSX" => "10.6", "Ubuntu" => "11.04", "Windows" => "7");
return array($s1, $s2, $s3);
}
function RelatedInStuff()
{
$value = array(getRelatedStuffInStuff());
foreach ($value as $key => $value)
{
echo "$key $value <br />\n";
}
}
?>
以上代码输出时为什么会网页显示空白,呵呵,那是因为html里没有调用函数呢。
需要在网页html代码里添加如下代码:
<html><body>
<?php
RelatedInStuff();
?>
</body></html>
标签: array
- 站长推荐