<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Converting arrays to human readable tables</title>
	<atom:link href="http://aidanlister.com/2004/04/converting-arrays-to-human-readable-tables/feed/" rel="self" type="application/rss+xml" />
	<link>http://aidanlister.com/2004/04/converting-arrays-to-human-readable-tables/</link>
	<description>Code is poetry</description>
	<lastBuildDate>Tue, 31 Jan 2012 07:34:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: steffens david</title>
		<link>http://aidanlister.com/2004/04/converting-arrays-to-human-readable-tables/comment-page-1/#comment-3519</link>
		<dc:creator>steffens david</dc:creator>
		<pubDate>Thu, 26 Jan 2012 17:08:02 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=59#comment-3519</guid>
		<description>Hello and thanks you. Seems it doesn&#039;t work for array of object. I try this :

function arrayToTable($array, $recursive = false, $null = &#039;&#160;&#039;)
{
    // Sanity check
    if (empty($array) &#124;&#124; !is_array($array)) {
        return false;
    }
 
    if (count($array) === 0) {
        $array[] = array();
    }
 
    // Start the table
    $table = &quot;\n&quot;;
 
    // The header
    $table .= &quot;\t&quot;;
 
    // Take the keys from the first row as the headings
    $first_row = current($array);
    if (is_object($first_row)) {
        $first_row = get_object_vars($first_row);
    }
    foreach (array_keys($first_row) as $heading) {
        $table .= &#039;&#039; . $heading . &#039;&#039;;
    }
    $table .= &quot;\n&quot;;
 
    // The body
    foreach ($array as $row) {
        $table .= &quot;\t&quot; ;
        foreach ($row as $cell) {
            $table .= &#039;&#039;;
 
            // Cast objects
            if (is_object($cell)) { $cell = get_object_vars($cell); }
 
            if ($recursive === true &amp;&amp; is_array($cell) &amp;&amp; !empty($cell)) {
                // Recursive mode
                $table .= &quot;\n&quot; . arrayToTable($cell, true, true) . &quot;\n&quot;;
            } else {
                $table .= (strlen($cell) &gt; 0) ?
                    htmlspecialchars((string) $cell) :
                    $null;
            }
 
            $table .= &#039;&#039;;
        }
 
        $table .= &quot;\n&quot;;
    }
 
    $table .= &#039;&#039;;
    return $table;
}</description>
		<content:encoded><![CDATA[<p>Hello and thanks you. Seems it doesn&#8217;t work for array of object. I try this :</p>
<p>function arrayToTable($array, $recursive = false, $null = &#8216;&nbsp;&#8217;)<br />
{<br />
    // Sanity check<br />
    if (empty($array) || !is_array($array)) {<br />
        return false;<br />
    }</p>
<p>    if (count($array) === 0) {<br />
        $array[] = array();<br />
    }</p>
<p>    // Start the table<br />
    $table = &#8220;\n&#8221;;</p>
<p>    // The header<br />
    $table .= &#8220;\t&#8221;;</p>
<p>    // Take the keys from the first row as the headings<br />
    $first_row = current($array);<br />
    if (is_object($first_row)) {<br />
        $first_row = get_object_vars($first_row);<br />
    }<br />
    foreach (array_keys($first_row) as $heading) {<br />
        $table .= &#8221; . $heading . &#8221;;<br />
    }<br />
    $table .= &#8220;\n&#8221;;</p>
<p>    // The body<br />
    foreach ($array as $row) {<br />
        $table .= &#8220;\t&#8221; ;<br />
        foreach ($row as $cell) {<br />
            $table .= &#8221;;</p>
<p>            // Cast objects<br />
            if (is_object($cell)) { $cell = get_object_vars($cell); }</p>
<p>            if ($recursive === true &amp;&amp; is_array($cell) &amp;&amp; !empty($cell)) {<br />
                // Recursive mode<br />
                $table .= &#8220;\n&#8221; . arrayToTable($cell, true, true) . &#8220;\n&#8221;;<br />
            } else {<br />
                $table .= (strlen($cell) &gt; 0) ?<br />
                    htmlspecialchars((string) $cell) :<br />
                    $null;<br />
            }</p>
<p>            $table .= &#8221;;<br />
        }</p>
<p>        $table .= &#8220;\n&#8221;;<br />
    }</p>
<p>    $table .= &#8221;;<br />
    return $table;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adrian</title>
		<link>http://aidanlister.com/2004/04/converting-arrays-to-human-readable-tables/comment-page-1/#comment-390</link>
		<dc:creator>Adrian</dc:creator>
		<pubDate>Tue, 21 Jun 2005 19:23:20 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=59#comment-390</guid>
		<description>Hello and thanks for the great work.
I made a patch that shows the datatype of the array-element as a tooltip. Just replace the else-part after &quot;if($recursive==true...&quot; with:

&lt;?php
$tooltip = &quot;gettype(): &quot;.strtoupper(gettype($cell));
$table .= &#039;&lt;span title=&quot;&#039;.$tooltip.&#039;&quot;&gt;&#039;.( (strlen($cell) &gt; 0) ?
htmlspecialchars((string) $cell) : $null) .&#039;&lt;/span&gt;&#039;;
?&gt;

regards,
adrian</description>
		<content:encoded><![CDATA[<p>Hello and thanks for the great work.<br />
I made a patch that shows the datatype of the array-element as a tooltip. Just replace the else-part after &#8220;if($recursive==true&#8230;&#8221; with:</p>
<p>&lt;?php<br />
$tooltip = &#8220;gettype(): &#8220;.strtoupper(gettype($cell));<br />
$table .= &#8216;&lt;span title=&#8221;&#8216;.$tooltip.&#8217;&#8221;&gt;&#8217;.( (strlen($cell) &gt; 0) ?<br />
htmlspecialchars((string) $cell) : $null) .&#8217;&lt;/span&gt;&#8217;;<br />
?&gt;</p>
<p>regards,<br />
adrian</p>
]]></content:encoded>
	</item>
</channel>
</rss>

