|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
change variable code doesn't work
Unfortunately, the code doesn't work. The variable does not change to Blueberry. It remains strawberry.
Quote:
|
|
#2
|
|||
|
|||
|
try this:
Code:
<?php
// set variable
$flavour = "strawberry";
// function to change variable value
function change_flavour($name)
{
$flavour = $name;
return $flavour;
}
echo "Before calling the function, the flavour is $flavour.<p>";
// change variable value
change_flavour("blueberry");
echo "After calling the function, the flavour is $flavour.";
|
|
#3
|
|||
|
|||
|
once again -- now, it is the right code
Code:
function change_flavour($name)
{
global $flavour; # add this line!
$flavour = $name;
return $flavour;
}
|
|
#4
|
|||
|
|||
|
yes, making $flavour global makes it work. Thanks.
|
|
#5
|
||||
|
||||
|
Or you could do this...
PHP Code:
__________________
Matt |
![]() |
| Viewing: Dev Shed Forums > Other > Development Articles > change variable code doesn't work |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|