I was wondering if there was a way that I can declare a variable at the top of my php file that contains some ‘array stuff’ and have it used in a foreach loop below somewhere?
For example:
$variable = 'Here is some text, and here is the value:'.$items->value.'.';
foreach ( $somearray as $items ) {
echo $variable;
}
*note: I am using ezsql for database actions, hence the $items->value variable….
Make sense? I’m just trying to make my file easy to change for other situations… or is there a better way?
Thanks for looking and for your help.
The nicest way to do this would, I think, be
printf. It’s not exactly what you asked for, but I think it will make your code cleaner.The value passed as the second argument to
printfwill be substituted into the code.