-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathshowarray.php
More file actions
53 lines (46 loc) · 1.55 KB
/
showarray.php
File metadata and controls
53 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Utility function to build HTML table from an array.
*
* Reference: http://www.terrawebdesign.com/multidimensional.php
*/
function htmlShowArray($array) {
html_show_array($array);
}
function html_show_array($array) {
echo "<table cellspacing='0' border='1'>\n";
show_array($array, 1, 0);
echo "</table>\n";
}
function show_array($array, $level, $sub) {
if (is_array($array) == 1) { // check if input is an array
foreach($array as $key_val => $value) {
$offset = "";
if (is_array($value) == 1){ // array is multidimensional
echo "<tr>";
$offset = do_offset($level);
echo $offset . "<td>" . $key_val . "</td>";
show_array($value, $level+1, 1);
} else { // (sub)array is not multidim
if ($sub != 1){ // first entry for subarray
echo "<tr nosub>";
$offset = do_offset($level);
}
$sub = 0;
echo $offset ."<td width='180px'>" . $value . "</td>";
echo "</tr>\n";
}
} //foreach $array
} else {
// argument $array is not an array
return;
}
}
function do_offset($level){
$offset = ""; // offset for subarry
for ($i=1; $i<$level;$i++) {
$offset = $offset . "<td></td>";
}
return $offset;
}
?>