Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.