|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
Codewalkers news w/ comments tut. Variable $all?
I'm kind of new to PHP and I was reading the News With Comments tutorial on this site and am trying to figure out from where does the script pull out the value of the $all variable:
Code:
function displayNews($all==0)
{
if($all==0){do something;}
else {do something else;}
}
Maybe I'm missing something extremely easy but I don't get this, like in my understanding the function will never do the 'else' part. where are the function pulling out the value for $all? |
|
#2
|
|||
|
|||
|
RE: Codewalkers news w/ comments tut. Variable $all?
the tutorial reads:
function displayNews($all = 0) not $all==0: The variable $all is being set in the function declaration. The = (equals) sign does assignment. The == does comparison. |
|
#3
|
|||
|
|||
|
RE: Codewalkers news w/ comments tut. Variable $all?
When you have a function, you can set variables to carry over, like:
In this, you must call it using myStupidFunction(something,something,something). However, if you do this: You can get away with only calling myStupidFunction(something). What the $fury = "2 Bits" and $ihatecereal = false do are set that variable *IF* you do not pass anything to it. Therefore, if you use myStupidFunction("Crap","Fury"), you get $crap = "Crap", $fury = "Fury", $ihatecereal = false. If you use myStupidFunction(16), then you get $crap = 16, $fury = "2 Bits", $ihatecereal = false. Those variables with = in the function call itself are only set if they are not passed over when called. Therefore, the else statement in what you posted would be set if someone called the function with something other than 0 for $all. |
|
#4
|
|||
|
|||
|
RE: Codewalkers news w/ comments tut. Variable $all?
Ah yeah my mistake, the function is:
function displayNews($all=0) But what I don't get is why have an if-else conditional if you are hardcoding the value of $all? |
|
#5
|
|||
|
|||
|
RE: Codewalkers news w/ comments tut. Variable $all?
oops.. please disconsider my previous post
Thanks Lizardman! |
![]() |
| Viewing: Codewalkers Forums > Other > Tutorials > Codewalkers news w/ comments tut. Variable $all? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|