Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Variable not being set/declared/called correctly?
    primarykey
    data
    text
    <p>I have part of a PHP script that's behaving odd for me. The below loop grabs the highest value from the <code>builds</code> array - which is a bunch of integers in a random order. It grabs the highest value as expected, no problems there. </p> <pre><code>$highest = $builds[0]; for ($i=0; $i &lt; count($builds); $i++) { if ($builds[$i] &gt; $highest) { $highest = $builds[$i]; } } </code></pre> <p>The problem is when I try to use <code>$highest</code> after the loop. (<code>file_get_html</code> is part of the simple_html_dom library - I use it fine in other parts of the script - it's not an issue.)</p> <pre><code>$html = file_get_html("http://www.blah.com/builds/" . $highest); //timeout msg on browser </code></pre> <p>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."</p> <p>I've played around a bit, and best I can tell is that <code>$highest</code> isn't being set or called correctly somehow.</p> <p>If I assign the variable manually, <code>file_get_html</code> works fine and returns data as expected. I.E. If I make my script looks like this.</p> <pre><code>$highest = $builds[0]; for ($i=0; $i &lt; count($builds); $i++) { if ($builds[$i] &gt; $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 </code></pre> <p>Why does manually assigning the variable work, but setting it in the loop doesnt? I've put in <code>prints</code> and <code>var_dumps</code> along the way to make sure the variable is being set correctly, and it appears to be. Mind boggled. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload