I have part of a PHP script that's behaving odd for me. The below loop grabs the highest value from the builds array - which is a bunch of integers in a random order. It grabs the highest value as expected, no problems there.
$highest = $builds[0];
for ($i=0; $i < count($builds); $i++) {
if ($builds[$i] > $highest) {
$highest = $builds[$i];
}
}
The problem is when I try to use $highest after the loop. (file_get_html is part of the simple_html_dom library - I use it fine in other parts of the script - it's not an issue.)
$html = file_get_html("http://www.blah.com/builds/" . $highest);
//timeout msg on browser
This ends up timing out. Chrome comes back with "Error 101: The connection was reset". Firefox comes back with a similar, "The connection to the server was reset while the page was loading."
I've played around a bit, and best I can tell is that $highest isn't being set or called correctly somehow.
If I assign the variable manually, file_get_html works fine and returns data as expected.
I.E. If I make my script looks like this.
$highest = $builds[0];
for ($i=0; $i < count($builds); $i++) {
if ($builds[$i] > $highest) {
$highest = $builds[$i];
}
}
$highest = 20; //I understand the loop is useless because of this
//but I've been running it to make sure it's not the issue.
$html = file_get_html("http://www.blah.com/builds/" . $highest);
//now this returns data
Why does manually assigning the variable work, but setting it in the loop doesnt?
I've put in prints and var_dumps along the way to make sure the variable is being set correctly, and it appears to be. Mind boggled.
$highest = intval($highest);after the loop.string '20' (length=2)@Chris, no dice. Forgot to mention I also tried doing (string) to no avail.