Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old December 27th, 2002, 08:17 PM
thms-mt thms-mt is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 9 thms-mt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old December 27th, 2002, 08:43 PM
bob0099 bob0099 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: manchester,n.h.,usa
Posts: 172 bob0099 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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.

Reply With Quote
  #3  
Old December 27th, 2002, 08:58 PM
Lizardman Lizardman is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 113 Lizardman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Codewalkers news w/ comments tut. Variable $all?

When you have a function, you can set variables to carry over, like:
php Code:
Original - php Code
  1. myStupidFunction($crap,$fury,$ihatecereal) { ... }

In this, you must call it using myStupidFunction(something,something,something).

However, if you do this:
php Code:
Original - php Code
  1. myStupidFunction($crap,$fury = "2 Bits",$ihatecereal = false) { ... }

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.

Reply With Quote
  #4  
Old December 27th, 2002, 09:04 PM
thms-mt thms-mt is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 9 thms-mt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?


Reply With Quote
  #5  
Old December 27th, 2002, 09:07 PM
thms-mt thms-mt is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 9 thms-mt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Codewalkers news w/ comments tut. Variable $all?

oops.. please disconsider my previous post

Thanks Lizardman!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Codewalkers news w/ comments tut. Variable $all?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway