Forum Moderators: coopster

Message Too Old, No Replies

Anybody know what this is doing

two = s in a define variable

         

prefict

1:55 am on Dec 11, 2004 (gmt 0)

10+ Year Member



got two lines in one piece of code doing this
$elements = $stack = array();
$total_elements = $total_chars = 0;

what is it doing

does it set $stack = Array();
and then set $elements = $stack;

or does it just set $elements as an array();
and $stack as another array()?

baze22

2:29 am on Dec 11, 2004 (gmt 0)

10+ Year Member



It's initializing variables. Setting $elements and $stack as arrays and $total_elements and $total_chars as numbers.

basil

Salsa

2:33 am on Dec 11, 2004 (gmt 0)

10+ Year Member



Yes!

They are just shortcuts to:

$elements = array(); //empty arrays
$stack = array();
$total_elements = 0; //empty variables
$total_chars = 0;
If you want to set a bunch of variables to empty strings, just:

$variable1 = $variable2 = $variable3 = $variable4 = $variable5 = $variable6 = $variable7 = "";
And, prefict, welcome to Webmaster World!

Salsa

2:34 am on Dec 11, 2004 (gmt 0)

10+ Year Member



You go Baze!

prefict

5:10 am on Dec 11, 2004 (gmt 0)

10+ Year Member



Thanks guys,

I am a .NET VB ASP developer started programming in perl 8 years ago but PHP is still new enough to me that short cuts like this one look strange. In asp or VB I'd use a similar model
dim var1,var2,var3 etc comas make sense but the ='s signs just seem very strange.

I am finding PHP to be nice OOP though, fits very cleanly into my .NET development understanding.

Thanks again for the input.

dcrombie

1:00 pm on Dec 15, 2004 (gmt 0)



The explanation is that: the return value of the assignment operation is the value being assigned.

;)