2

I have a code to generate php code from an array of words, however the list of words is variable like:

    $list=array(
    "BMW",
    "MUSTANG",
    "DBM",
    "Txt62"
    );

$arrlength=count($list);

for($x=0;$x<$arrlength;$x++)
  {
  echo ' \'' .$list[$x]. '\'' . ' => $this->input->post("'.$list[$x].'") == \'\' ? \'Not defined definido\' : $this->input->post("'.$list[$x].'"),  ';
  echo "<br>";
  }

Is there a better way to do it, like a function that I pass the array of words, and it returns php code?, Is this possible inside php code?

7
  • 4
    github.com/ircmaxell/PHPPHP Commented May 11, 2013 at 20:25
  • Not sure what's the problem ? Commented May 11, 2013 at 20:32
  • from an array of words, I want to generate php code for each of those words, the problem is, I can not make dynamic php code..} Commented May 11, 2013 at 20:34
  • @cMinor ok, you want a new .php file, what does that PHP file do ? Commented May 11, 2013 at 20:35
  • It catches post values from all fields given a table in MYsql, then generates a code to validate all of the fields Commented May 11, 2013 at 20:42

1 Answer 1

1

It's not easy to understand what you're trying to do, but if it is to run a function on every item in an array, you can use array_walk for that ?

$list = array(
              "BMW",
              "MUSTANG",
              "DBM",
              "Txt62"
             );

function validate($item, $key) {
    echo ' \'' .$item. '\'' . ' => $this->input->post("'.$item.'") == \'\' ? \'Not defined definido\' : $this->input->post("'.$item.'"),  <br>';
}

array_walk($list, 'validate');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.