for loop - Concatenation of a dynamic integer value in a php function -
i trying print dynamic values , using utilize foreach(). here code trying. original code have integrate , create dynamic loop runs 4 times. have alter print_static_1_container print_static_$i_container.
<?php if(!function_exists('print_static_1_container')) { function print_static_1_container() {
this code trying:
<?php for($i=1;$i<=4;$i++) { $function = create_function('$i', 'echo "print_static_{$i}_container";'); function $function() { global $site; ?> <!-- static 1 container --> <!-- ********************************************* start ************************************************* --> <div class="static-<?php echo $i; ?>-home"> <div class="row"> <div class="gal-head home-section-head"> <?php if(isset($site['theme_options']->static_$i_html_content) && !empty($site['theme_options']->static_$i_html_content)) echo $site['theme_options']->static_$i_html_content; ?> </div> </div> </div> <?php } } ?>
the error
unexpected '.' in line function print_static_.'$i'._container()
should be:
$function_name = "print_static_$i_container"; if(!function_exists($function_name)) { $function_name = function() { // stuff };
you can phone call function this: $function_name();
you can utilize variables within double quotes only. php interprets single-quoted strings appear, is, value stored in variable not replaced in string.
php for-loop
No comments:
Post a Comment