RSilva
RSilva

Reputation: 6943

My script stops after a foreach loop

My script is acting strange. After a foreach loop, the script stops. I don't have any error, any warning or notice from Apache. This is the code:

foreach($clientFact as $line)
{
    $cliTemp1[] = $line["idcliente"];
    echo "qwerty";
}
echo "123";

If I add an "echo(qwerty")" inside the loop, it will show the "qwerty" but, right after the end of the loop it will not do anything.

Am I missing something?!

Thanks

Upvotes: 3

Views: 1935

Answers (3)

Ozzy
Ozzy

Reputation:

Apache wouldnt return an error as its a PHP error. Adding

error_reporting(E_ALL | E_STRICT);

on the top of your page is a very good idea so you can see every error that happens. It could also be your error handler that is not displaying the error and just ending the script.

If it is a problem with your error handler, add

restore_error_handler();

before the error_reporting function

Edit: read your comment about the array index. It definately sounds like a memory limit being reached in PHP if it stops at a specific index every time.

You could use:

ini_set('memory_limit', '100M');

to change your memory limit to 100megs. Not recommended but if it works, its a problem with not enough memory. Try to refactor your program so it uses less memory

Upvotes: 9

chaos
chaos

Reputation: 124267

At a guess, you're dying on an error inside the loop because one of your $lines isn't an array like you expect, and the error is being hidden. Try setting error_reporting(E_ALL) before the loop, and possibly ini_set('display_errors', true).

Upvotes: 2

ConroyP
ConroyP

Reputation: 41896

The syntax above looks fine, so as a complete shot in the dark here - how big is the $clientFact array? Is it possible that the $cliTemp1 array is getting so large it's tripping a memory limit?

Maybe rather than echoing "qwerty", echo out the contents of $line["idcliente"] on each iteration to be sure you're successfully getting through all elements in $clientFact.

Upvotes: 4

Related Questions