Page 1 of 1
Variables inside Variables.
Posted: Sat Aug 06, 2011 5:13 am
by ThatPerson
I was wondering how I would be able to set and get a variable with a variable name. I was wondering if there was a way to do something like:
Code: Select all
<?php
$a = "Hello";
${$a."Hi"} = "Goodbye";
echo ${$a."Hi"};
?>
So you could retrieve variables from inside a for loop?
Re: Variables inside Variables.
Posted: Sat Aug 06, 2011 6:13 am
by oscardog
This should answer your questions.
Re: Variables inside Variables.
Posted: Sat Aug 06, 2011 6:23 am
by ThatPerson
Ah, thanks. I had a look and now know what I was looking for.
Re: Variables inside Variables.
Posted: Sat Aug 06, 2011 6:34 am
by ThatPerson
Instead of creating a new thread, I was wondering if anyone here would know why this:
Code: Select all
$num = ${p.$a."pos"};
$len = ${p.$a."len"};
$named = ${p.$a};
$test = mysql_query("select friendrequests from notes_notes where email = '$usr' and Password = '$pwd'") or die(mysql_error());
$test3 = mysql_fetch_object($test);
$test4 = $test3 -> friendrequests;
$namen = $named.",";
$test2 = str_replace("",$namen,$test4);
echo $test2;
mysql_query("UPDATE notes_notes SET friendrequests = '$test2' WHERE email = '$usr' and Password = '$pwd'") or die(mysql_error());
$tes = mysql_query("select friendrequests from notes_notes where email = '${$named}'") or die(mysql_error());
$tes3 = mysql_fetch_object($tes);
$tes4 = $tes3 -> friendrequests;
$tes2 = str_replace($namen,"",$tes4);
mysql_query("UPDATE notes_notes SET friendrequests = '$tes2' WHERE email = '${$named}'") or die(mysql_error());
Would return the same text as before instead of $tes4 without $namen included? ($tes4 because I had used test, and $namen because I was running out of ideas for name).