Hacker News new | past | comments | ask | show | jobs | submit login

It's actually slightly wrong to just say "variables start with $". It's more like "$ dereferences a string":

  $foo = "I am foo\n";
  $bar = "foo";
  echo $$bar;
This is in the documentation under "variable variables" [0]. This also lets you create dynamic function names:

  function run_foo() {
      echo "I'm a foo\n";
  }

  $method = 'foo';  
  $picked = "run_$method";
  $picked();
[0] https://www.php.net/manual/en/language.variables.variable.ph...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: