用另一个数组填充数组
我这里遇到麻烦了!我有一个函数可以验证 XML 文件是否有错误。如果该函数找到它,我会将错误保存在一个数组中,以便在成功(非错误)结果后打印错误。
但是为了打印错误,对于每个循环,我打印一个 div,显示错误,但这些 DIV 必须完全打印并显示发现的所有错误!我不知道这是否很清楚,但我将展示一些代码来帮助理解。
在这里,我将所有错误放入数组中
$value = the results inside the error search on the XML
foreach($values as $founderrors){
$founderrors= array($valores);
}
好的,现在我在这里有这个:
if ($values["erro"]==true) {
$divErro1 = '<div> lololol </div>';
$erros = array($divErro1,$divErro2);
foreach($valores as $testeste){
$testeste = array($erros);
}
return true;
这就是我填写“Div 错误”的地方
在代码中我有这个:
print_r($testeste);
打印数组!
但它只显示最后一个“Error Div”!我认为当我需要打印包含所有错误的所有 div 时,他正在替换找到的 div 并仅显示最后一个。啊,忽略 Div 的内容,里面还有另一个代码来显示相应的错误。
有人可以帮我吗?多谢! =]
I got a trouble here! I have a function that verify an XML file for errors. If the function finds it, I save the errors in one Array to print the errors after the successfull (non error) results.
But to print the errors, for each loop, I print a div, showing the errors, but these DIV's must be printed at all and showing all errors found! I dont know if that was very clear, but i'll show a bit of code to help the understanding.
Here, I put inside the array all the errors
$value = the results inside the error search on the XML
foreach($values as $founderrors){
$founderrors= array($valores);
}
Ok, now here i have this:
if ($values["erro"]==true) {
$divErro1 = '<div> lololol </div>';
$erros = array($divErro1,$divErro2);
foreach($valores as $testeste){
$testeste = array($erros);
}
return true;
That is where i fill the "Div errors"
And down the code i have this:
print_r($testeste);
To print the array!
But it only shows the last "Error Div"! I think he's replacing the found divs and showing the last one only, when i need to print all divs containing all errors. Ah, just ignore the content of the Div, there's another code inside it to show the respective error.
Could anyone give me a help? Thanks a lot! =]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有正确填充数组,请查看
http://php. net/manual/de/language.types.array.php
了解有关数组的更多信息。
例如:
在这里,您使用
array($erros)
覆盖之前的$testeste
。所以你实际上并没有收集任何东西。如果你想收集数组中的数据,你必须添加到数组中,例如
或
You're not filling your arrays correctly, have a look at
http://php.net/manual/de/language.types.array.php
to learn more about arrays.
For example:
Here your overriding whatever
$testeste
was before, witharray($erros)
. So you're not actually collecting anything.If you want to collect data in an array, you'll have to add to the array, like for example
or
您可以使用 [] 填充数组。例如:
You can populate arrays using []. For example: