Bluehost.com Web Hosting $6.95

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; Hello, This is a reply to an e-mail that you wrote on Tue, 15 Jul 2003 at 15:19, ...


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
David Nicholson
 
Posts: n/a
Default Re: [PHP] variable sized arrays & global vars - another newbie question

Hello,

This is a reply to an e-mail that you wrote on Tue, 15 Jul 2003 at 15:19,
lines prefixed by '>' were originally written by you.
> 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?


For me, the following code:

===
$counter=0;

function IncCounter(){
global $counter;
$counter++;
}

IncCounter();
echo $counter; // 1 is displayed
===

works fine, maybe it is a problem with your particular code?

David.

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
http://www.quizsender.com/
(developed entirely in PHP)
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 07:23 AM.


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