GargantulaKon Posted December 28, 2009 Share Posted December 28, 2009 OK, this is confusing so here is what I am trying to do: I am trying to pass a variable that I want to resolve inside another function. How do I do so? Doing the code below actually outputs the PHP code. I tried using the code without escaping, but then the variables are not resoloved. Am I doing it the wrong way? function Select_Star($Star_Type) { switch ($Star_Type) { case "E": $HTML = '<img id="Rating_\' . $i . \'" \' . $OnClick . \' onmouseover="Rating(\' . $i . \');" onmouseout="Rating();" src="/Images/Rating_Empty.png" alt="\' . $i . \' Star\' . Add_S($i) . \'" title="\' . $i . \' Star\' . $s . \'" />'; break; } return $HTML; } function Rating_HTML($Rating_Number, $User_Mood_ID, $Activated) { for ($i = 1; $i <= 5; $i++) { $Return .= Select_Star("E"); } } Link to comment https://forums.phpfreaks.com/topic/186479-passing-variables-in-a-variable-that-is-inside-another-function/ Share on other sites More sharing options...
abazoskib Posted December 28, 2009 Share Posted December 28, 2009 what exactly is your goal Link to comment https://forums.phpfreaks.com/topic/186479-passing-variables-in-a-variable-that-is-inside-another-function/#findComment-984704 Share on other sites More sharing options...
GargantulaKon Posted December 28, 2009 Author Share Posted December 28, 2009 I want $i to be resolved when it is inside the loop. I am trying to prevent having to retype the same HTML code over and over and instead pick from a switch depending on the case. Link to comment https://forums.phpfreaks.com/topic/186479-passing-variables-in-a-variable-that-is-inside-another-function/#findComment-984706 Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 You would need to make your Select_Star() function except another param. eg; function Select_Star($Star_Type, $i) Then call it..... for ($i = 1; $i <= 5; $i++) { $Return .= Select_Star("E", $i); } Link to comment https://forums.phpfreaks.com/topic/186479-passing-variables-in-a-variable-that-is-inside-another-function/#findComment-984708 Share on other sites More sharing options...
GargantulaKon Posted December 28, 2009 Author Share Posted December 28, 2009 Thanks! Wow, great idea! I just had a duh moment! It must be because I am been programming all day today... Link to comment https://forums.phpfreaks.com/topic/186479-passing-variables-in-a-variable-that-is-inside-another-function/#findComment-984709 Share on other sites More sharing options...
GargantulaKon Posted December 28, 2009 Author Share Posted December 28, 2009 I got it working now. Thanks thorpe for helping with my code. I will be sure to keep this in mind for future issues. Link to comment https://forums.phpfreaks.com/topic/186479-passing-variables-in-a-variable-that-is-inside-another-function/#findComment-984711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.