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!
Bu开发者_高级运维t 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! =]
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:
$testeste = array($erros);
Here your overriding whatever $testeste
was before, with array($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
$testeste[] = $erros;
or
array_push($testeste, $erros);
You can populate arrays using []. For example:
if ($values["erro"]==true) {
$divErro1 = '<div> lololol </div>';
$erros = array($divErro1,$divErro2);
foreach($valores as $testeste){
$testeste[] = $erros;
}
return true;
精彩评论