使用object / s递归数组 [英] Recurse an array with an object/s
问题描述
您好,
我使用的是php4
我有一个类产品
我创建了一个包含2个维度的productObjects数组。
Generraly我正在对数组中的对象进行排序,我需要一些
来计算这些数组来获取对象。
为此,我使用以下方法recurseArray()
函数recurseArray($ array){
if(is_array($ array)){
foreach($ array as $ arrayValue){
recurseArray($ arrayValue);
}
}
elseif(is_object($ array)){
$ object = $ array;
返回$ object;
}
}
问题就是当我尝试做的时候
$ _product = recurseArray($ productArray)
print_r($ _ product);
它不会刺激任何东西。但是,如果我在方法内部做的话就像
那样
....
elseif(is_object($ array)){
$ object = $ array;
print_r($ object)
返回$ object;
}
....
它会打印我的物品。
你知道为什么会这样吗?
它让我疯了!!!
谢谢,Angelos。
数组){
if(is_array(
array)){
foreach(
array as
Hello,
I am using php4
And I have a class product
I create an array of productObjects that has 2 dimensions.
Generraly I am sorting my objects inside arrays and I need to some how
recurse those arrays to get to the objects.
To do that I am using the following method recurseArray()
function recurseArray($array) {
if(is_array($array)) {
foreach($array as $arrayValue) {
recurseArray($arrayValue);
}
}
elseif(is_object($array)) {
$object = $array;
return $object;
}
}
the problem with that is that when i try to do
$_product = recurseArray($productArray)
print_r($_product);
it won''t pring anything. But if i do the pring inside the method like
that
....
elseif(is_object($array)) {
$object = $array;
print_r($object)
return $object;
}
....
it will print my object.
Do you know why is this happening ?
It makes me crazy !!!
Thanks, Angelos.
array) {
if(is_array(
array)) {
foreach(
array as
这篇关于使用object / s递归数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!