【发布时间】:2013-09-13 04:31:00
【问题描述】:
我的功能正在输出它应该输出的内容。当我运行这个程序时,我得到的只是“就在那时,众神伸出手,决定给予力量来帮助完成这项任务。”如何让它从两个数组中选择相同的索引并填充回显中的变量?
function gift_giver()
{
$people = array ("$heroname", "$friendname", "$wizardname", "Captain Rumbeard", "$frogname");
$gifts = array("a magic compass", "the gift of no fear", "all seeing powers", "more rum", "a delightful lilly pad");
$gift_selector=(rand(0,4));
$gift_recipient=$people[$gift_selector];
$gift_present=$gift[$gift_selector];
echo "It was then that the gods reached out and decided to give $gift_recipient the power of $gift_present to aid in this quest.<br/><br/>";
}
【问题讨论】:
-
一方面,它应该是
$gifts,而不是$gift。 -
我在编辑中修复了这个问题;等待批准....
-
@GeorgeBrighton 你不应该在编辑中修复错误。
-
$heroname在哪里定义?在你的职能之外?
标签: php function variables random