php - How to insert data from the included file and create HTML-elements automatically? -


I want to insert data from the included file and automatically create HTML-elements.

I have data.php :

  $ vps_de_dc1_s1 = array ("name" => "Germany, DC1, before "," Value "= & gt;" 10â ?? ",); $ Vps_de_dc1_s2 = array ("name" => gt; "germany, dc 1, second", "value" => "10 â ?? ¬",); $ / Vps_de_dc2_s1 ..., $ vps_cz_dc1_s1 ..., $ vps_cz_dc12_s1 ..., etc  

and in the page. Php should be there: Include

  ('data.php'); & Lt; Tr class = "vps_de_dc1" & gt; & Lt; Td square = "column-left" & gt; Name & lt; / Td> & Lt; Td square = "column-right" & gt; $ Vps_de_dc1_s1 ["name"] & lt; / Td> & Lt; Td square = "column-right" & gt; $ Vps_de_dc1_s2 ["name"] & lt; / Td> & Lt; Td square = "column-right" & gt; $ Vps_de_dc1_s3 ["name"] & lt; / Td> & Lt; / TR & gt; & Lt; Tr class = "vps_de_dc2" & gt; & Lt; Td square = "column-left" & gt; Name & lt; / Td> & Lt; Td square = "column-right" & gt; $ Vps_de_dc2_s1 ["name"] & lt; / Td> & Lt; Td square = "column-right" & gt; $ Vps_de_dc2_s2 ["name"] & lt; / Td> & Lt; Td square = "column-right" & gt; $ Vps_de_dc2_s3 ["name"] & lt; / Td> & Lt; / TR & gt; ...   

I want to know, is it possible to automate the construction of any type of table elements here?


Update: In fact, echo is for me to create all the table instances but I have all these & lt; Tr class = "vps _ * _ dc *" & gt; ... & lt; / Tr & gt; Automatically by each $ vps _ * data.php

First start with data.php. Below, add a master array of all your arrays:

  $ masterArray = array ('vps_de' => array ('DC' = & gt; 2, 's' = & gt; ; 4), // key is the original name. 'Vps_cz' = & gt; array ('DC' => 2, 's' => 4), // How much DC and S value are present per location . // This example implies that it is 2Dc and 4S for the 8 possible arrays you have defined ... ...); Pages in   

Php:

  foreach ($ masterArray $ varName => $ infoArray) // Repetition via the master list. {$ ($ Dc = 1; $ dc & lt; = $ infoArray ['dc']; $ dc ++) // To the DC limit though iterated through many numbers. {$ ClassName = $ varName '_dc' $ DC; // Create the name of the class, which is the composited space key root with the DC number. Echo & lt; Tr class = "'. $ ClassName." "For the echo of the table's line ($ s = 1; $ s & lt; = $ infoArray ['s']; $ s ++) // Still limit the number through many numbers {$ ArrayName = $ className '_s' $ S; // Creating the name of variable, reference of the array. If (isset ($$ arrayName)) // Checking to see if we just created the name The variables are present. {$ TmpArray = $$ arrayName; // Using a variable using a variable variable to rearrange the array using its name, echo & lt; td class = "column-left" & gt; ; Echo $ tmpArray ['name']; // I think You can use $ $ arrayName ['name'] here, but it can be secured in $ tmpArray echo & lt; / td & gt; ';}} echo & lt; / tr & gt; ;}}   

Edit: After reading some more of your question, it appears that your needs are more complex than before.

Hopefully That this is what you are

Good luck!

Comments