p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Global Variables


Message #1 by "Jon Shoreman" <Jon.Shoreman@b...> on Mon, 4 Feb 2002 00:24:31
If a variable is declared in the main body of the program $var=1 and you 

want to access it from within a function I know you use the following 

syntax $GLOBALS["var"]



But how do you access global arrays from within a function?



For example;

$myarr[1]="Apples";

$myarr[2]="Oranges";



How would I access $myarr[n] from within a function, when I want to use a 

local variable to replace n, i.e. $myarr[$mypointer] ??



Message #2 by "Hermawan Haryanto" <hermawan@h...> on Mon, 4 Feb 2002 07:56:08 +0700
after you declase a function, then do global statement,  then you will can

use the array on your function

sample



$myarr[1]="Apples";

$myarr[2]="Banana";

function something(){

  global $myarr;

  ...



}



Thanks

Hermawan Haryanto



----- Original Message -----

From: "Jon Shoreman" <Jon.Shoreman@b...>

To: "beginning php" <beginning_php@p...>

Sent: Monday, February 04, 2002 12:24 AM

Subject: [beginning_php] Global Variables





> If a variable is declared in the main body of the program $var=1 and you

> want to access it from within a function I know you use the following

> syntax $GLOBALS["var"]

>

> But how do you access global arrays from within a function?

>

> For example;

> $myarr[1]="Apples";

> $myarr[2]="Oranges";

>

> How would I access $myarr[n] from within a function, when I want to use a

> local variable to replace n, i.e. $myarr[$mypointer] ??

>

>




$subst('Email.Unsub').

>



Message #3 by "Jon Shoreman" <Jon.Shoreman@b...> on Mon, 4 Feb 2002 20:11:59
Thanks Hermawan 

  Return to Index