make variable from foreach result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RobbertvanOs
Forum Newbie
Posts: 9
Joined: Wed Jul 02, 2003 2:43 pm

make variable from foreach result

Post 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
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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
RobbertvanOs
Forum Newbie
Posts: 9
Joined: Wed Jul 02, 2003 2:43 pm

Post 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
Post Reply