Quantcast
Viewing latest article 2
Browse Latest Browse All 5

Answer by Sean McSomething for how to create and concatenate dynamic variables in PHP?

Whenever somebody says "dynamic variables" it's a big red flag. You can do them but it's a bad idea 99% of the time. What you're probably looking for is an array. If you write:

$menus = array();while($parent_row = mysql_fetch_array($parent_result)){    $menus[$i] = "\n\t$('#menu_" . $i . "').hover(function () {";}echo $menus[1];echo $menus[2];echo $menus[3];

You'll get what you're after without delving into the maintenance headache & potential disaster that dynamic variable names would give you. You can also easily loop over $menus which makes things nice when you suddenly have 2, 4 or 40 different elements.


Viewing latest article 2
Browse Latest Browse All 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>