Re: Variable scope in loops

From: Date: Tue, 31 Jul 2001 21:49:49 +0000
Subject: Re: Variable scope in loops
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-8601@lists.php.net to get a copy of this message
Whoops, my mistake. I read your code completely wrong. Ignore my comments. You are calling the first variable but I didn't expect it to be called like that. I expected that the array would be appended to by calling it like this: $incident_array[]=$value; Nevermind, sorry 'bout that. Paul Smith wrote: > > Well, first of all, to get the first value of the array you should call > it as $incidnet_array[0]. Now doing that *might* fix your problem if you > were only recieving one value for the array. So if you were getting > output inside the array, how many outputs were you getting? One or two > or more? > > ~Paul > > Tom Tsongas wrote: > > > > Hi folks. > > > > I have an interesting problem with regards to variable scope in loops. > > Now I understand how this operates in functions but its the first time I > > have seen variable scope in a loop. > > > > Below is a code snippet of what I have: > > > > // execute SQL query > > OCIExecute($sql_statement) or die("Couldn't execute statement."); > > > > // get number of columns for use later > > $num_columns = OCINumCols($sql_statement); > > > > // format results by row > > while (OCIFetch($sql_statement)) { > > for ($i = 1; $i < $num_columns+1; $i++) { > > // Create array to store fetch results > > $incident_array[i] = OCIResult($sql_statement,$i); > > //echo "<P>Incident array value $i: $incident_array[i]</P>"; > > > > } > > } > > // Output results of incident array > > echo "<P>First array value: $incident_array[1]</P>"; > > > > Now I 'expected' the echo statement to properly display the results of > > the first array element but instead, the value is blank. Now when I > > uncomment the echo statement WITHIN the for loop, it does display so I > > know the values are being stored but apparantly the scope of the array > > is within the loop and not outside. > > > > How can I make the array values accessible outside of the loop? I found > > a 'global' statement in the documentation but it didn't seem to like > > taking an array as a parameter. I had it looking something like this: > > > > global $incident_array[]; > > > > Any help would be appreciated. > > > > Tom Tsongas > > > > -- > > PHP Windows Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > > For additional commands, e-mail: php-windows-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > Paul Smith > psmith@dostuff.net > http://www.dostuff.net > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- Paul Smith psmith@dostuff.net http://www.dostuff.net

« previous php.windows (#8601) next »