php - Deciphering a function -


Some time ago, this function was posted in response to a question. As a learner, I am interested in understanding the ceremony. However, I can not get it to work as it is. The poster did not say that he had tested this event, so it could have a "conceptual" post to show the direction. Otoh, I can not apply it correctly Please help because I have spent some time trying to understand it.

($ data array is the one that I've put to run the function.)

  & lt; ? Php $ data = array ("a" = & gt; "january", "b" => "February", "c" => "march"); Render_table ($ data); $ Echo echo; // =========================================== Function render_table ($ data ) {$ Html = '& lt; Table & gt; '; $ Tr = array (); $ Currency as foreign currency (Aria_Keys ($ data [0]) {$ tr [] = '& lt; Th & gt; . Htmlspecialchars ($ key) '& lt; / Th & gt; '; } $ Html = "\ N". '& Lt; Thead & gt; . "\ N". '& Lt; TR & gt; . "\ N". Implode ("\ n", $ tr). '& Lt; / TR & gt; . '& Lt; / Thead & gt; '; $ Corpus = array (); Forex currency ($ data as $ line) {$ tr = array (); Forex Currency ($ R $ as Value) {$ tr [] = '& lt; Td> . Htmlspecialchars ($ value) '& lt; / TD & gt; '; } $ When [] = '& lt; Tr & gt; . "\ N". Implode ("\ n", $ tr). '& Lt; / TR & gt; '; } $ Html = "\ N". '& Lt; Tbody & gt; . "\ N". Implode ("\ n", $ $ tbody) '& lt; / Tbody & gt; '; $ Html = '& Lt; / Table & gt; '; Return $ Html; }? & Gt;  

First of all, your data is incorrect function as an array form of an argument Takes in

Note the line

  foreach (array_keys ($ data [0]) as the $ {{code /  

... This function call is also incorrect; it should not take the first element, it should take the entire array, because it is using the keys from the array.

Try it: First, use the entire array Change the call to array_keys, foreach (array_keys ($ data as $ key)

Then change your input and function call: < / P>

  $ data = array ('data1' = & gt; array ('one', 'two', 'ti Array '(' four ',' five ',' six '), data 3' = & gt; array ('seven', 'eight', 'nine')); 'data' Echo render_ table ($ data);  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -