我正在使用laravel和php,我正在做一个递归函数,问题是该函数的return
值不能正常工作echo
。
代码就是这个。
public function getSitioPadre($id){
$padre = md_sitio_espacios::where([['SITIO_ESPACIOS_ID','=',$id]])->get()->toArray();
if($padre[0]["PADRE"] == 0){
return $padre[0]["SITIO_ESPACIOS_ID"];
}else{
$this->getSitioPadre($padre[0]["PADRE"]);
}
}
当我称这个函数为:
echo $this->getSitioPadre(54);
什么都不返回,
如果在我使用的函数中使用:echo $padre[0]["SITIO_ESPACIOS_ID"]
而不是return
,则可以使用。
让我知道我能做些什么,谢谢。
答案 0 :(得分:4)
你似乎没有在你的其他条款中返回任何内容。
# 1
# Compiles. On Windows throws System.InvalidCastException:
# 'Unable to cast object of type 'Xamarin.Forms.Binding'
# to type 'System.Boolean'.'
<ActivityIndicator x:Name="AI" IsEnabled="{Binding Path=IsBusy}" IsRunning="{Binding Path=IsBusy}">
<ActivityIndicator.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Android" Value="True"/>
<On Platform="iOS" Value="True"/>
<On Platform="Windows" Value="{Binding Path=IsBusy}"/>
</OnPlatform>
</ActivityIndicator.IsVisible>
</ActivityIndicator>
# 2
# Doesn't compile. Gives an error saying "No property,
# bindable property, or event found for 'IsVisible'"
<ActivityIndicator x:Name="AI" IsEnabled="{Binding Path=IsBusy}" IsVisible="True" IsRunning="{Binding Path=IsBusy}">
<ActivityIndicator.IsVisible>
<OnPlatform x:TypeArguments="BindingBase">
<On Platform="Windows" Value="{Binding Path=IsBusy}"/>
</OnPlatform>
</ActivityIndicator.IsVisible>
</ActivityIndicator>
# 3
# Doesn't compile. Gives an error saying "No property,
# bindable property, or event found for 'IsVisible'"
<ActivityIndicator x:Name="AI" IsEnabled="{Binding Path=IsBusy}" IsVisible="True" IsRunning="{Binding Path=IsBusy}">
<ActivityIndicator.IsVisible>
<OnPlatform x:TypeArguments="Binding">
<On Platform="Windows" Value="{Binding Path=IsBusy}"/>
</OnPlatform>
</ActivityIndicator.IsVisible>
</ActivityIndicator>
# 4
# Compiles. On Windows throws System.InvalidCastException:
# 'Unable to cast object of type 'Xamarin.Forms.Binding'
# to type 'System.Boolean'.'
<ActivityIndicator x:Name="AI" IsEnabled="{Binding Path=IsBusy}" IsVisible="True" IsRunning="{Binding Path=IsBusy}">
<ActivityIndicator.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Windows">
<Binding Path="IsBusy" />
</On>
</OnPlatform>
</ActivityIndicator.IsVisible>
</ActivityIndicator>