while loop - Modifying PHP code of an Include, outside of the include? -


i want set php variable: $custom, used whenever defined.

but want output of variable dependant of variable: $v index, used inside while, gets defined during while statement.

i don't know if it's possible do, right have following code, , way defined $custom[3], doesn't work.

only $custom[1] , $custom[2] varibables work, take account constant values or variable values set, isn't helpful.

code:

<?php  $product[1]["price"]=10; $product[2]["price"]=50; $product[3]["price"]=70;  $custom[1] = 'static html block'; $custom[2] = 'past variable: '. $product[2]["price"] .''; $custom[3] = 'future variable: '. $product[$v]["price"] .''; // want kind of definitoin  ?>  <html>  // following part used within include, , shouldn't modified ///  <?php   $v = 1;   while ($z <= 5) {   ?>  <?= $custom[$v] ? $custom[$v] : '$' . $product[$v]["price"] ?>  <?php   $v = $v + 1; $z = $z + 1;  }   ?>  

so basically, want on third run (when v=3), future variable: 70 output.

the rationale:

i want use latter code constant include, serve template files. on occasion, file may require special changes require php code modification, want perform them within such specific file, affect original include.

edit 2:

more simple example:

<?php  $product[1]["price"]=10; $product[2]["price"]=50;  $custom[1] = 'i dont modify php code'; $custom[2] = 'i mofiy latter php code: '. $product[$v]["price"] .''; ?>  <html>  // following part used within include, , shouldn't modified ///  <?php $v = 1; while ($v <= 5) { ?>  <?= $custom[$v] ?> <p>  <?php $v = $v + 1; } ?>  // expected output:  //i dont modify php code //i mofiy latter php code: 50 

it's little difficult tell trying do, think need decouple data presentation:

$product[1]['price']=10; $product[2]['price']=50; $product[3]['price']=70;  $custom[1] = 'static html block'; $custom[2] = 'past variable: %s'; $custom[3] = 'future variable: %s';  $v = 1; while($z <= 5) {     $price = $product[ $v ]['price'];     printf($custom[ $v ], $price);     $v++;     $z++; } 

in case, $custom stores format, doesn't contain data. call printf output desired format whatever data want pass.


Comments