plz help me here

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nishafav
Forum Newbie
Posts: 1
Joined: Thu Dec 30, 2010 5:35 am

plz help me here

Post by nishafav »

can any1 plz help me write this code...

i want to print the valu of variable z.
there are three variables x, y and z

x is initialized some where else...
y=x z=z+y

first call of function x=10 y=10 z=10
second call x=20 y =20 z=20+10
third call x=30 y= 30 z=30+30
fourth call x=40 y=40 z=90+40

and so on
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: plz help me here

Post by Darhazer »

Code: Select all

function z($x) {
   static $z = 0;
   $z += $x;
   echo $z;
}

z(10);
z(20);
z(30);
z(40);
Post Reply