Hi there,

I'm new to OOP in PHP and was wondering if you could help me. I have a script I would like to put into a function, inside a class. It basically sets the name of a variable depending on the value of another variable

var $i="h";
var $r=i."h";
var $$r="hello world";

I would be very greatfull if someone could tell me how to do this. I've searched the net and these forums but with no luck. As I said I'm new to this. If someone can help I would be most greatfull.

-Steve

    I don't quite get what you mean so i hope this helps:

    $NameOfVar = "var123";
    	$$NameOfVar = "hello";
    	echo $var123;
    
    //Thrown in a function
    
    function setVarToVal($var, $val){
    	global $$var;
    	$$var = $val;
    }
    
    setVarToVal("VAR456", "world");
    echo $VAR456;
    

    Hope that helps you out.

      Excelent, that was just what I was looking for. Thanks

      All the best

      -Steve

        No problem,

        Hope you stick around
        Bookmark this site 🙂

          Write a Reply...