|
|
|
|
|
通過使用如下三個函數(shù),獲得數(shù)組array的數(shù)據(jù)。
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";
}
}
?>
以上代碼輸出時為什么會網(wǎng)頁顯示空白,呵呵,那是因為html里沒有調(diào)用函數(shù)呢。
需要在網(wǎng)頁html代碼里添加如下代碼:
<html><body>
<?php
RelatedInStuff();
?>
</body></html>