html - Dynamic generated accordion from php array -
Heilo
I have a problem, I am noob in PHP and I want to generate ampersons from dynamic array (0 = & gt; array ('name' = & gt; 'name1') this php array. / P>
$ main = array ('mainregion1' => Array ('main_person' =>, 'phone' => '000000000', 'email' = & gt; Name = name.com ',' important '=> true,),),' subregion1 '=> array (0 = & gt; array (' name '= & gt;' name2 ',' phone '= & Gt;' 000111000 ',' email '= & gt;' name2@name2.com ',' important '=>, wrong), 1 => array (' name '= & gt;' Name '3', 'phone' => '000222000', 'email' = & gt; 'name3@name3.com', 'important' =>, incorrect)), 'sub-rule 2' = & G Array (0 = & gt; array ('name' = & gt; 'name 4', 'phone' => '111000111', 'email' = & gt; 'name4@name4.com', ' Important '=> false;),),),); Array ('mainregion2' = & gt; array ('main_person' => array (0 = & gt; array ('name' = & gt; 'name1', 'phone' => '000000000', 'Name' = & gt; 'name@name.com', 'important' =>, true),), 'sub-rule1' = & gt; array (0 = & gt; array ('name' = & Gt; 'name2', 'phone' => 000111000, 'email' => 'name2@name2.com', 'critical' =>, 1 = & gt; ; Array ('name' = & gt; 'name3', 'phone' => '000222000', 'email' = & gt; 'name3@name3.com', 'important' = & gt; wrong, ), 'Subregion2' = & gt; array (0 = & gt; array ('name' = & gt; 'name4', 'phone' => '111000111', 'email' = & gt; 'Name4@name4.com', 'critical' = & gt; wrong,))),));); I have done it in html. I want to display the data as "parent" tag as a parent from the "main" array and display it content, and Data from the array of sub-markets below shows in accordance with the children's divisions.
But I do not know Php and O how to do it, I have tried the foreach function, but I did not understand that the mood-a-provision is good and play with them.
Can anyone help me with it?
Something like this index might not be right because I do not see the dimension clearly in your array can.
Edit: Take care with your array change it:
'subregion2' = & Gt; Array (0 = & gt; array ('name' = & gt; 'name4', 'phone' => '111000111', 'email' = & gt; 'name4@name4.com', 'important' = & Gt; wrong,),),))); Array (with 'mainregion2' = & gt; array ('main_person' => array (// code ... ):
'Subregion2' = & gt; array (0 = & gt; array ('name' = & gt; 'name4', 'phone' => '111000111', 'email' = & gt; 'name4 @ name4 .com ',' important '=> gt; array) (' main_person ' If not, then you are declaring an array without the key or the variable.
Try it, tested it on my localhost, and do it
$ foreach $ $ as $$ => key == 'main_person') {echo " Cho "& lt; p & gt; Name -". $ Value [0] ['name']. "& Lt; / p & gt;"; Echo "& lt; p & gt; Phone -". $ Value [0] ['Phone']. "& Lt; / p & gt;" echo "& lt; p & gt; Email -". $ Value [0] ['email'] "; Echo" & lt; h3 & Gt; $ of & lt; / h3 & gt; "; if" "; echo" & lt; / div> "echo" (size ($ Value)> 1) {$ subReg = $ value; Forex Currency ($ sub $$ sK => $ SV) {resonance ""; Echo "& lt; p & gt; name -". $ SV ['name'] "& Lt; / p & gt;"; Echo "& lt; p & gt; phone -". $ SV ['phone']. "& Lt; / p & gt;"; Echo "& lt; p & gt; Email -". $ SV ['email']. "& Lt; / p & gt;"; Echo "& lt; / div & gt;"; }} Else {echo ""; Echo "& lt; p & gt; name -". $ Value [0] ['name']. "& Lt; / p & gt;"; Echo "& lt; p & gt; phone -". $ Value [0] ['phone']. "& Lt; / p & gt;"; Echo "& lt; p & gt; Email -". $ Value [0] ['email']. "& Lt; / p & gt;"; Echo "& lt; / div & gt;"; }} Echo ""; }? & Gt;
Comments
Post a Comment