Jump to content

[SOLVED] variable variable array not working


shocker-z

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.