我有以下代码:
echo "Size of array: " . sizeof($userDetails) . $this->newline;
foreach($userDetails as $i) {
echo "Item: " . $i . $this->newline;
}
......当我跑步时,我得到了
数组大小:1 Item:Array
要尝试显示数组,我将其更改为:
echo "Size of array: " . sizeof($userDetails) . $this->newline;
foreach($userDetails as $a) {
foreach($a as $i) {
echo "Item: " . $i . $this->newline;
}
}
这似乎有效,我得到以下输出:
Size of array: 1
Item: Graham
Item: Graham
Item: XYZ
Item: XYZ
Item: 180337955-yu29UNDy8idaryz9ilkXCVTo7Osjus76RWEud5ZU
Item: 180337955-yu29UNDy8idaryz9ilkXCVTo7Osjus76RWEud5ZU
Item: HyMkKJWISYHSLSSHS89261702id54Fjr7uKSUS8yo
Item: HyMkKJWISYHSLSSHS89261702id54Fjr7uKSUS8yo
Item: PihJSISJ8MgpkJS8S7xgyA
Item: PihJSISJ8MgpkJS8S7xgyA
Item: JS87SGSKSHJJSLKIUKJjhsllsjkjskjkjlEDTxyQ
Item: JS87SGSKSHJJSLKIUKJjhsllsjkjskjkjlEDTxyQ
Item: pid.bjk
Item: pid.bjk
您将看到每个项目(正确显示)都会重复(不应该重复)。这表明我使用的是错误的。
有人能告诉我我是如何正确使用foreach的吗?
提前谢谢。