shocker-z Posted January 3, 2008 Share Posted January 3, 2008 Hi there ive created an application which has been compiled to exe using http://www.bambalam.se/bamcompile/ Im passing variables and then exploding them down to the values i need and the output of this is correct but i cant get my variable variable array to work $search_replace=array('Student reference', 'Surname', 'Forename'); $search_with=array("file['ref']", "file['surname']", "file['forename']"); $searchfield=str_replace($search_replace,$search_with,$searchoption); if ($searchstring == $$searchfield) { //the code to be processed } if i echo $searchfield before the if statement then it will echo the correct values (1 of the 3 values withing $search_with) but if i use $$search_with it echo's back blank. The array exists and if i use the following then it works fine if ($searchstring == $file['ref']) { Regards Liam Link to comment https://forums.phpfreaks.com/topic/84296-solved-variable-variable-array-not-working/ Share on other sites More sharing options...
shocker-z Posted January 3, 2008 Author Share Posted January 3, 2008 After trying ${$searchoption} and a few other things i decided i would try creating a function, and this works fine for me function searchfor($option) { global $file; switch($option) { case 'StudentReference' : return $file['ref']; break; case 'Forename' : return $file['forename']; break; case 'Surname' : return $file['surname']; break; } } then called with if (strtolower($searchstring) == strtolower(searchfor($searchoption))) { Works fine for what i need, just posted incase someone needs a way around it one day and is a bit slow and special like myself. Regards Liam Link to comment https://forums.phpfreaks.com/topic/84296-solved-variable-variable-array-not-working/#findComment-429365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.