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:
  #1  
Old December 27th, 2002, 09: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, 09: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: 3
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, 09: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: 3
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, 10: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, 10: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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek