If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

I don't understand this operator..

As the title says, i really don't understand the = assignment operator and how it works i've been told that the = operator takes what's on the right and shoves it to the left but i really don't understand why it does that and how to use the = operator but I'm sure I'm about to find out hehe

Users who have thanked djm0219 for this post:

The = operator just takes whatever is on the right hand side of the = and puts it into the left hand side variable. However, you must ensure that the value on the right hand side is the same as the value capable to be held on the left hand side. For example, if you were to have x = 1, you must ensure that x is of an integer type otherwise the 1 cannot be stored in it.

You would find that the = operator is very useful, and you will use it in pretty much every programming language code you write. You use to it to assign values to variables where you can later use those variables to perform tasks.

For example:xz = 5*3
andxy = 5*7
You could then write to work out xz+xy:xz + xy rather than (5*3)+(5*7), which is not only quicker but can be useful for pieces of code which require the same value repeatedly.

I am being very basic about it and using very basic examples. You will find that with more complicated code the = method can even be used to make variables hold values from methods.

However, you must ensure that the value on the right hand side is the same as the value capable to be held on the left hand side. For example, if you were to have x = 1, you must ensure that x is of an integer type otherwise the 1 cannot be stored in it.

PHP defaults to pass by value on everything except for objects in post-PHP5. Pre-PHP5, objects were also pass by value, so it was necessary to handle function return references as well (this is more of an argument handling for functions, but you get the point).

PHP Code:

$a = 10;
$b = &$a;

print $a . "\n"; // 10
print $b . "\n"; // 10

$a = 0;
print $a . "\n"; // 0
print $b . "\n"; //0

So when its said that the value of the right is stuffed into the left, is an incorrect way of perceiving a variable. As you can see above, $b is not stuffed with $a, $b is provided with a pointer that references the same memory location held by $a. Any changes in $a are reflected into $b, though changes in $b will not be reflected into $a.

Understand?

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)