Display array in list (collapsable)
Display array in print_r
Display array in ul li
Display array in pre
Usually in programming, when you debugging an array you will be using the pre and print_r
This is all right when the data is small. But if the array size is very large things will be hard which is happen to me lately.
So I create a function that display the array on the list. Plus this list is collapsible and it is a very simple code. Only 2 function needed
Usually in programming, when you debugging an array you will be using the pre and print_r
This is all right when the data is small. But if the array size is very large things will be hard which is happen to me lately.
So I create a function that display the array on the list. Plus this list is collapsible and it is a very simple code. Only 2 function needed
function thejavascriptrewrite(){echo "<script type='text/javascript'>";echo "function switchme( \$theId){\$theElement = document.getElementById(\$theId);if( \$theElement.style.display == 'none'){\$theElement.style.display = '';}else{\$theElement.style.display = 'none';}}";echo "</script>";}function arraytolist( $data, $iteration = 0, $fortheUL = null){$idName = "someCounterId";echo "<ul $fortheUL>";foreach( $data as $key => $value){if( !is_array($value)){echo "<li>";echo "[$key]=".$value;echo "</li>";}else{$iteration++;$totalArray = count( $value);echo "<li>"."<a onclick=\"switchme('$idName".$iteration."')\">$key ($totalArray)</a>";$forNextUL = "id='$idName".$iteration."' style='display: none;'";$iteration = arraytolist($value, $iteration, $forNextUL);echo "</li>";}}echo "</ul>";return $iteration;}
How to use?
paste this code
$data = array( 'abc', 'def', 'ghi');thejavascriptrewrite();arraytolist($data);
No comments:
Post a Comment