cmaier Posted August 13, 2006 Share Posted August 13, 2006 Ok... so i have a very large block of code (the majority of my page) enclosed in a string that i print later on...[code]<?php$temp_code_block = <<<TEMP_CODE_KEYWORD.... some html & php code.... foreach loop goes here.... more html & phpTEMP_CODE_KEYWORD;echo $temp_code_block;?>[/code]Everything works fine except i can't figure out how to use loops within that string (a foreach loop specifically)...Since i'm already in a <?php tag and it wouldn't make sense to open another, how would i make "foreach" be recognized as a php reserved word and execute it as a loop?Thanks - cmaier Link to comment https://forums.phpfreaks.com/topic/17440-foreach-loop-inside/ Share on other sites More sharing options...
toplancers Posted August 13, 2006 Share Posted August 13, 2006 try to use { and } even its a single line loop...Thank you,http://TopLancers.comCreate your profile Today!http://TopLancers.com/forum join now Link to comment https://forums.phpfreaks.com/topic/17440-foreach-loop-inside/#findComment-74226 Share on other sites More sharing options...
cmaier Posted August 13, 2006 Author Share Posted August 13, 2006 I do... heres the code near the foreach...[code] <TR> <TD> <UL class='menu_inner_list'> foreach ($global_site_left_column_menu_2_content_array as $global_site_left_column_menu_2_item) { <LI> <A class="$global_site_left_column_menu_2_item[2]" href="$global_site_left_column_menu_2_item[1]">$global_site_left_column_menu_2_item[0]</A> </LI> } </UL> </TD> </TR>[/code]... but it just outputs it as if it were text.. when you view the page you see...foreach (Array as ) {} Link to comment https://forums.phpfreaks.com/topic/17440-foreach-loop-inside/#findComment-74230 Share on other sites More sharing options...
hostfreak Posted August 13, 2006 Share Posted August 13, 2006 Post the array as well please. Link to comment https://forums.phpfreaks.com/topic/17440-foreach-loop-inside/#findComment-74234 Share on other sites More sharing options...
cmaier Posted August 13, 2006 Author Share Posted August 13, 2006 I don't see how the contence of the array is related to my question.. but here it is...[code]$global_site_left_column_menu_2_content_array = array( array('Link One', 'http://mydomain.com/subfolder/', 'default_menu'), );[/code]My problem is that foreach(){} is not being interpreted as php code... my only question is how do i make the loop be parsed as php. Link to comment https://forums.phpfreaks.com/topic/17440-foreach-loop-inside/#findComment-74243 Share on other sites More sharing options...
cmaier Posted August 13, 2006 Author Share Posted August 13, 2006 Ok... to simplify what i'm trying to get accomplished i just wrote a small example (using if else this time)Original Source:[code]<HTML><?php $var1 = "THIS IS TEXT";?><BODY> <?php $code_block = <<<KEYWORD <H1>TEST H1</H1> if (!$var1) { <H2>TEST H2</H2> } else { <H2>$var1</H2> }KEYWORD;echo $code_block; ?></BODY></HTML>[/code]View-Source of Output[code]<HTML><BODY> <H1>TEST H1</H1> if (!THIS IS TEXT) { <H2>TEST H2</H2> } else { <H2>THIS IS TEXT</H2> }</BODY></HTML>[/code]If you just show me how to make the if/else function as php code i'll be able to figure it out for my foreach example... i just can't find a way to make this work. Link to comment https://forums.phpfreaks.com/topic/17440-foreach-loop-inside/#findComment-74246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.