Passing in Arguments

Reply

Join Date: Jul 2007
Posts: 91
Reputation: Reliable is an unknown quantity at this point 
Solved Threads: 2
Reliable Reliable is offline Offline
Junior Poster in Training

Passing in Arguments

 
0
  #1
Oct 8th, 2009
Good afternoon all,

I'm at the beginning stages of learning PHP. I'm trying to understand passing in functions. I have a video lesson so I can see what is being explained but for some reason i am still not getting it.
  1. <?php
  2. function hello($word)
  3. {
  4. echo "Hello {$word}!<br/>";
  5. }
  6.  
  7. hello("Daniweb");
  8. ?>
Can someone possibly explain it in a way that I would? This will also help me better understand ActionScript 3.0 Thanks.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,435
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 232
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is online now Online
Code Monkey
 
0
  #2
Oct 8th, 2009
What exactly don't you understand? You have a function 'hello' that takes 'name' as a parameter. Any time you call hello and pass it a value, in this case Daniweb it will use that value as the value of the parameter name.

  1. function hello($name)
  2. {
  3. echo 'Hello, ' . $name;
  4. }
  5. hello('Daniweb');
  6.  
  7. // is exactly like saying
  8. echo 'Hello, ' . 'Daniweb';
  9. // since the value of $name becomes 'Daniweb'
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 91
Reputation: Reliable is an unknown quantity at this point 
Solved Threads: 2
Reliable Reliable is offline Offline
Junior Poster in Training

Gotcha. Thanks!

 
0
  #3
Oct 8th, 2009
Originally Posted by ShawnCplus View Post
What exactly don't you understand? You have a function 'hello' that takes 'name' as a parameter. Any time you call hello and pass it a value, in this case Daniweb it will use that value as the value of the parameter name.

  1. function hello($name)
  2. {
  3. echo 'Hello, ' . $name;
  4. }
  5. hello('Daniweb');
  6.  
  7. // is exactly like saying
  8. echo 'Hello, ' . 'Daniweb';
  9. // since the value of $name becomes 'Daniweb'
I guess perhaps the semantics of everything was messing me up (eg.."passing in", "arguments"). It wasn't that specific example I had problems with; it was the general principal of "passign in arguments": why that needs to happen; what makes that pertinent/significant/needed. I just posted that to try and make sure people were clear what I was asking. Perhaps I failed in that. As I changed semantics in my head the bright light shone. As i rephrase "passing in arguments" with "receiving variables" and received the lesson a few more times I got it. Thanks for your time and clarity though. See you at the top.
Last edited by Reliable; Oct 8th, 2009 at 3:34 pm. Reason: further information
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 191 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC