我有以下数组:
$users
: array =
0: array =
0: object(Person) =
strName: string = John
strLastName: string = Smith
strAge: string = 19
1: object(Person) =
strName: string = Jean
strLastName: string = Newton
strAge: string = 22
1: array =
0: object(Person)=
strName: string = John
strLastName: string = Smith
strAge: string = 19
1: object(Person) =
strName: string = Jean
strLastName: string = Newton
strAge: string = 22
2: array =
0: object(Person) =
strName: string = Martin
strLastName: string = Marin
strAge: string = 25
为了摆脱我所做的重复:
$users = array_map("unserialize", array_unique(array_map("serialize", $users)));
我得到:
$users
: array =
0: array =
0: object(Person) =
strName: string = John
strLastName: string = Smith
strAge: string = 19
1: object(Person) =
strName: string = Jean
strLastName: string = Newton
strAge: string = 22
1: array =
0: object(Person) =
strName: string = Martin
strLastName: string = Marin
strAge: string = 25
现在我必须获取数组包含的信息。我正在做:
$i=0;
foreach ($users as $u)
{
echo $u [$i]->getName());
.
.
$i++;
}
但我没有打印数组的所有元素,$u [2] 是 NULL。
我做错了什么?
万分感谢!