Php 不返回变量的函数
目前我对两个函数有一些问题;我试图让数组从第一个函数传递到另一个函数,但由于某种原因,我无法让它工作Php 不返回变量的函数,php,Php,目前我对两个函数有一些问题;我试图让数组从第一个函数传递到另一个函数,但由于某种原因,我无法让它工作 function getResourceXML($id) { $xml = simplexml_load_file('resources.xml'); foreach($xml->children()->children() as $children) { if($children['id'] == $id) {
function getResourceXML($id)
{
$xml = simplexml_load_file('resources.xml');
foreach($xml->children()->children() as $children)
{
if($children['id'] == $id)
{
$resource[] = $children["income"];
return $resource;
}
}
}
function getResourceMultiplier()
{
$sql = "SELECT resourceArray FROM starinformation WHERE starOwner = :uid";
$que = $this->db->prepare($sql);
$que->bindParam('uid', $this->uid);
try
{
$que->execute();
while($row = $que->fetch(PDO::FETCH_BOTH))
{
$resource = $this->getResourceXML($row[0]);
return $resource;
}
}
catch(PDOException $e) {}
}
将两个函数中的
return
语句移动到循环}
之后,否则只会得到一次循环迭代。另外,在getResourceMultiplier()
中,您没有创建数组。您需要(或类似):
这些是在类中使用的吗?您是
$this
,但未提供类代码here@helion3是的,他们是。。抱歉,半个睡眠应该提到你正在调试输出吗?返回值是有条件的,因此如果条件失败,您将看不到它。另外,while循环中有一个返回
,这意味着它只运行一次$row[0]
?不应该仅仅是$row
?“试图获得要传递的数组”是一个输入错误,因为您传递的不是数组,而是数组元素。
$resource[] = $this->getResourceXML($row[0]);