PHP Classes

Tip for figuring out the array hierarchy / structure

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Tip for figuring out the array...  >  (Un) Subscribe thread alerts  
Subject:Tip for figuring out the array...
Summary:Use print_r() to get a better view of the arrays
Messages:1
Author:Will Scott
Date:2010-04-27 01:51:18
 

  1. Tip for figuring out the array...   Reply   Report abuse  
Picture of Will Scott Will Scott - 2010-04-27 01:51:18
First off, thank you so much for this class! It is a big help!

I found a few messages posted to the forum looking for instructions or syntax for getting one item from parsed messages, such as just the message body in unformatted text. I was struggling with the same, my eyes would glaze over a bit as I tried to glean the structure of the arrays from the var_dump provided in the sample. I used the print_r() function in php to get a better view of the data and multidimensional arrays, finding it quite helpful.

In the for($message = 0; $message < count($decoded); $message++) loop (in the provided sample), I added the following after the var_dump():

echo "<BR><BR>PRINT_R of decoded: ";
echo "<pre>";
print_r($decoded);
echo "</pre>";

For message bodies, I added similar code after var_dump($results).

echo "<BR><BR>PRINT R of results: ";
echo "<pre>";
print_r($results);
echo "</pre>";

Information on how the print_r() function works is available at:
php.net/manual/en/function.print-r. ...

Print_r with the <pre> tags creates "human-readable," hierarchical, view of the variable dump. After passing a few messages to it, I was able to get a good enough start on understanding the structure to dig further.