问题描述
也许我根本无法理解PHP如何处理数组。
Perhaps I'm simply having trouble understanding how php handles arrays.
我想打印出来使用foreach循环数组。所有我似乎可以摆脱它是单词阵列。
I'm trying to print out an array using a foreach loop. All I can seem to get out of it is the word "Array".
<?php
$someArray[]=array('1','2','3','4','5','6','7'); // size 7
foreach($someArray as $value){
echo $value;
?>
<br />
<?php
}
?>
本打印出来的:
Array
我无法理解为什么会出现这种情况。如果我定义数组前面像上面,它会打印出阵。它几乎好像我有手动定义一切......这意味着我必须做一些错误的。
I'm having trouble understanding why this would be the case. If I define an array up front like above, it'll print "Array". It almost seems like I have to manually define everything... which means I must be doing something wrong.
本作品:
<?php
$someArray[0] = '1';
$someArray[1] = '2';
$someArray[2] = '3';
$someArray[3] = '4';
$someArray[4] = '5';
$someArray[5] = '6';
$someArray[6] = '7';
for($i=0; $i<7; $i++){
echo $someArray[$i]."<br />";
}
?>
为什么不能在foreach工作?
Why won't the foreach work?
这里有一个链接,看到它在行动>>
here's a link to see it in action >> http://phpclass.hylianux.com/test.php
推荐答案
您没有正确申报的数组。结果
你要删除的方括号: []
You haven't declared the array properly.
You have to remove the square brackets: []
.
<?php
$someArray=array('1','2','3','4','5','6','7'); // size 7
foreach($someArray as $value){
echo $value;
?> <br />
<?php
}
?>
这篇关于PHP的foreach回声照片和QUOT;数组&QUOT;作为价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!