When a function's parameter contains a variable
Posted: Sun Jan 25, 2009 4:19 pm
I need to pass a string to a function that contains code.
Part of the code is a variable. ($number)
The code needs to be evaluated in the function and return another string.
I would expect the following code to print out
"The number is 123. It is passed from the function. "
but it prints out
"The number is $number. It is passed from the function. "
I am sure I am doing something simplely wrong????
Part of the code is a variable. ($number)
The code needs to be evaluated in the function and return another string.
I would expect the following code to print out
"The number is 123. It is passed from the function. "
but it prints out
"The number is $number. It is passed from the function. "
I am sure I am doing something simplely wrong????
Code: Select all
<html>
<body>
<?php
$test = 'The number is $number. It is passed from the function. ';
$tempStr = showNumber($test); // this is function shown below
echo($tempStr);
// -----------------------------
function showNumber($t)
{
$number = 123;
$outString = $t;
return $outString;
}
?>
</body>