Re: Can i take the variable name in a function?
| From: | Andy Hultgren | Date: | Wed, 11 Oct 2006 17:06:17 +0000 |
| Subject: | Re: Can i take the variable name in a function? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-242990@lists.php.net to get a copy of this message | ||
Check this out: http://www.php.net/manual/en/functions.arguments.php
Specifically this example:
Making arguments be passed by reference
By default, function arguments are passed by value (so that if you change
the value of the argument within the function, it does not get changed
outside of the function). If you wish to allow a function to modify its
arguments, you must pass them by reference.
If you want an argument to a function to always be passed by reference, you
can prepend an ampersand (&) to the argument name in the function
definition:
*Example 17-6. Passing function parameters by reference*
<?php
function add_some_extra(&$string)
{
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'?> I think that does what you want? Andy On 10/11/06, Jônata Tyska Carvalho <jonatatyska@gmail.com> wrote:
I know that function does not work, but im asking if someone know a way to do that. Someone know how ??? On 10/11/06, Andy Hultgren < wearhdphp@gmail.com> wrote: ummmm.... no... I suppose I should have though! :) On 10/11/06, Jochem Maas <jochem@iamjochem.com > wrote:Andy Hultgren wrote:How can i take the variable name inside a function, ex: definition: function example( $ex ){ echo "Variable Name is $ex "; // how to do this? } use: example($ball); output: Variable Name is ball; another: example($sportCar); output: Variable Name is sportCar; is that possible?Would something like this work?did you try it? ;-) it won't workDefinition: function example($$ex) { echo "Variable Name is $ex"; } example($ball); I'm fairly new to php and not so familiar with variable variables,but Ithought I'd throw it out there as a thought! Andy On 10/11/06, *Jochem Maas* < jochem@iamjochem.com <mailto: jochem@iamjochem.com>> wrote:Jônata Tyska Carvalho wrote:no.-- Jônata Tyska Carvalho ----------------------------------------------------------------- -- Técnico em Informática pelo Colégio Técnico Industrial (CTI) -- Graduando em Engenharia de Computação Fundação Universidade Federal de Rio Grande (FURG)-- PHP General Mailing List ( http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php