Hi, I'm just learning php now for the first time and I'm having a little
trouble understanding something.
In the following example:
------------------------------------------------------------------------
<?php
function test ($thenum) {
$funct = create_function ("\$thenumbe r", "return (\$thenumber+5) ;");
echo $funct($thenum) ;
}
test(5);
?>
------------------------------------------------------------------------
I don't understand why the escape characters are necessary here. I
understand that the create_function () function requires its parameters
to be in string format, but if my $thenum variable is an integer and not
a string, why is the \ necessary?
Furthermore, why does this next single quote version work without the \:
------------------------------------------------------------------------
<?php
function test ($thenum) {
$funct = create_function ('$thenumber', 'return ($thenumber+5); ');
echo $funct($thenum) ;
}
test(5);
?>
------------------------------------------------------------------------
Is this behavior something I will encounter often in php, because I
never had this confusion doing javascript or actionscript?
Help would be appreciated.
Keith
trouble understanding something.
In the following example:
------------------------------------------------------------------------
<?php
function test ($thenum) {
$funct = create_function ("\$thenumbe r", "return (\$thenumber+5) ;");
echo $funct($thenum) ;
}
test(5);
?>
------------------------------------------------------------------------
I don't understand why the escape characters are necessary here. I
understand that the create_function () function requires its parameters
to be in string format, but if my $thenum variable is an integer and not
a string, why is the \ necessary?
Furthermore, why does this next single quote version work without the \:
------------------------------------------------------------------------
<?php
function test ($thenum) {
$funct = create_function ('$thenumber', 'return ($thenumber+5); ');
echo $funct($thenum) ;
}
test(5);
?>
------------------------------------------------------------------------
Is this behavior something I will encounter often in php, because I
never had this confusion doing javascript or actionscript?
Help would be appreciated.
Keith
Comment