0

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.

<?php
function hello($word)
{
echo "Hello {$word}!<br/>";
}

hello("Daniweb");
?>

Can someone possibly explain it in a way that I would? This will also help me better understand ActionScript 3.0 Thanks.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Reliable
0

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.

function hello($name)
{
  echo 'Hello, ' . $name;
}
hello('Daniweb');

// is exactly like saying
echo 'Hello, ' . 'Daniweb';
// since the value of $name becomes 'Daniweb'
0

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.

function hello($name)
{
  echo 'Hello, ' . $name;
}
hello('Daniweb');

// is exactly like saying
echo 'Hello, ' . 'Daniweb';
// 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.

Edited by Reliable: further information

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.