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.

Recommended Answers

All 2 Replies

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'

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.