/    Sign up×
Community /Pin to ProfileBookmark

eval() function

Hi.
Does the PHP eval() function work in a similar way the javascript version?

I have the following function:
function altercolour($colour1, $colour2, $colour3) {
}
If the value “green” is given to $colour1, I want to perform alterations to the variable $green, and if “blue” is submitted the function would alter $blue…. etc.

Is this possible with eval(), in a similar way to javascript? Or can anyone suggest a better way to do this?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@redijediJul 11.2004 — I'm not quite sure what you mean by your example, but eval() lets you evaluate a string as if it were php code.

From php manual:

[code=php]
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "n";
eval("$str = "$str";");
echo $str. "n";
[/code]


Returns:

This is a $string with my $name in it.

This is a cup with my coffee in it.
Copy linkTweet thisAlerts:
@clairec666authorJul 11.2004 — Thanks alot........ I understand it now. I'm guessing you've read the example on php.net too!
×

Success!

Help @clairec666 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...