php foreach value loop of variables in file.php instead of array -


i'm trying find way create foreach loop can echo values, can in array, issue (as far know) cannot echo them variables name.

example right now:

<?php $stuff = array( foo => "<a href=\"/foo\">foo</a>", bar => "<a href=\"/bar\">bar</a>", thing => "thing", ); ?>  <?php foreach($stuff $val) {     print '<li>' . $val . '</li>'; } ?> 

my issue is, can't echo 1 of these name anywhere <?php echo $foo; ?> if stored variables. can tell, echo them number <?php echo $stuff[1]; ?>

what want store variables in file file.php , still able foreach loop above.

example:

<?php $foo = "<a href="/foo">foo</a>"; $bar = "<a href="/bar">bar</a>"; $thing = "thing"; ?> 

pseudo code of want:

<?php foreach(var in /path/to/file.php $value) {     print '<li>' . $value . '</li>'; } ?> 

how can foreach loop through variables in included file.php?

my recommendation use array. can foreach() on , access items directly:

echo $stuff['foo']; 

Comments

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -