Page 1 of 1

make variable from foreach result

Posted: Tue Nov 04, 2003 2:48 pm
by RobbertvanOs
Hi there,

i am trying to get a variable out of a result from a for each loop. So i build my table structure with everything in it. The result of this i want to put into a variable so it can be replaced in a template.

So far i used

echo stripslashes(str_replace(array('###MENU###','###TEXT###'),array("THIS SHOULD BE A VARIABLE INSTEAD OF TEXT",$replace2),$message));

Who can help me out and tell me how to do this?

Kind regards

Robbie

Posted: Wed Nov 05, 2003 9:12 am
by kendall
Robbie,

Uhm robbie...i think you need to be a lil more elaborate on your question but

Code: Select all

foreact($item_in_array as $key => $array_val){
echo stripslashes(str_replace($search,$array_val,$subject));
}
see i dont no what your $array_val is but it seems to be an inner array to $item_in_array and it seems your subject is a string of text

if your search is and array with the template markings then you need to go trhough some order sorting usually you try to replace $array_val with the corresponding $search[$key] that's if every thing is sorted/ organised in a certain order

i hope im not going off base here but perhaps you can follow or me more detailed

Kendall

Posted: Wed Nov 05, 2003 9:19 am
by RobbertvanOs
Hi kendall,

Thank you for your answer, i had a very unclear question about my loop. I found out that the problem wasn't in there, but the problem was the way i build a variable. I set a variable in a loop and everytime i looped over it, it resetted itself. I found out that i had to set the variable empty before the loop and that after that the variable summing up worked.

So thank you for your quick response and as soon as i have another question i'll be back ;)

Many thanks,

Kind regards,

Robbie