PDA

View Full Version : Can someone please explain?


Boofo
07-15-2002, 11:48 PM
Can someone please tell me if I am right in figuring out this line of code below? I am just using an example, but I want to see if what I think I learned is what actually is. :)

(I know this sounds pretty basic to most of you, but I want to learn this stuff and I have to start somewhere, I guess) :)

Here is the code:

if ($post[userid]!=$bbuserinfo[userid] and $bbuserinfo[canreportposts]==1)

Now, if I read this right, it means that if the post does NOT belong to the user, and they ARE able to report posts, then display whatever template you want to display. Does the "!=" mean not where "==" means does? Or can you use a single "=" to do the same thing? If I want to make it so it would display the template if it WAS the user's post, would I do this?

if ($post[userid]==$bbuserinfo[userid] and $bbuserinfo[canreportposts]==1)

If there is another way of doing this, too, please tell me. :) I'll take all of the help in understanding this I can get.

Indy
07-15-2002, 11:56 PM
I believe that you are correct with your explanation of the logic of the line of code.

!= Does not equal
if(1 != 2) would return true

== Equals
if(1 == 2) would return false

You use = when assigning a variable.

Boofo
07-16-2002, 12:07 AM
Thank you very much. :) Now all I need to figure out is what you mean by the "=" being used to assign a variable. Can you please give me an example? :)

Originally posted by Indyshooter
I believe that you are correct with your explanation of the logic of the line of code.

!= Does not equal
if(1 != 2) would return true

== Equals
if(1 == 2) would return false

You use = when assigning a variable.

Admin
07-16-2002, 06:27 AM
$foo = 'bar';
You don't want to use = in conditionals, at least not for now. If you do this:
if ($foo = 'bar') {
It will be true, since $foo is assigned 'bar', and since the assigment was successful the whole expression returns true (yes, assigments return true/false).

Boofo
07-16-2002, 07:35 AM
Ok, now I see what you mean. It's almost like Turbo Pascal when you assign the variables then. And if I wanted to assign a global variable to be able to use anywhere on the site, is global.php where I would put it or could it be done in functions.php?

(I love this stuff! :))

Originally posted by FireFly
$foo = 'bar';
You don't want to use = in conditionals, at least not for now. If you do this:
if ($foo = 'bar') {
It will be true, since $foo is assigned 'bar', and since the assigment was successful the whole expression returns true (yes, assigments return true/false).

Also, just to make sure I got it. these next 2 lines of code will actually return the same results, right?
if ($post[userid]!=$bbuserinfo[userid] and $bbuserinfo[canreportposts]==1) {

if ($post[userid]!=$bbuserinfo[userid] and $bbuserinfo[canreportposts]!=0) {