Re: [PHP] variable sized arrays & global vars - another newbie question

This is a discussion on Re: [PHP] variable sized arrays & global vars - another newbie question within the PHP General forums, part of the PHP Programming Forums category; Thanks for the reply! I must admit i and confused by the answer to the global variables question. Can i ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-15-2003
Bob pilly
 
Posts: n/a
Default Re: [PHP] variable sized arrays & global vars - another newbie question

Thanks for the reply!

I must admit i and confused by the answer to the global variables question.
Can i ask another question? What if i want to increment a global counter from within a function. at the moment i am trying to declare the variable normally:

$counter=0;
then within the function:
function (){
global $counter;
$counter++;
}

but then when i go to echo $counter outside of the function its value hasnt changed?
Yet again any help would be appreciatted!



Dirk Kredler <dirk@computication.net> wrote:
Am Dienstag, 15. Juli 2003 14:39 schrieb bob pilly:
> Can i declare an array that doesnt have a fixed size? Basically i want to
> assign the results of a query to the array but obviously the query results
> can change. Something along the lines of:


$myarray= array();

> while($temp=mssql_fetch_array($tmresult)){
> brandnew array = $temp["fieldname"];


$myarray[]= $temp["fieldname"];

> }


> this doesnt work for me, any ideas?
> Also is it possible to have global variables within php? I have noticed
> that if i create a function i cant write to what i thought were global
> variables(declared outside the function). Im not trying to pass variables
> between pages, just use a global counter within a single page?


$globalvar= 'Hi there';

function afunction() {
global $globalvar;

echo($globalvar);

}



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




---------------------------------
Want to chat instantly with your online friends?*Get the FREE Yahoo!Messenger
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:25 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0