
| Don't forget about PRE |
|
|
|
|
Okay so this isn't a PHP basic tip but when used in conjunction with other PHP function this can help draw out the results in a readable format. Have you ever wanted to know what exactly was in an array? I do all the time and I used to write recursive function to help get that information. Well then when I started to use objects and mixed these with arrays things started to get dicy and my recursive function pucked on me. So a good friend turned me onto this really great function called print_r. Yes it does everything I used to code into my functions and more. The other part I like is when PHP get modified I don't have to rewite my recursive function anymore because print_r is already supported and will be upgraded at the same time. Now then the output from print_r is formated nicely exept for one problem, browsers. They always read all white space as one space so normally looking at this code looks like junk. So here is where the pre tag come is. Try this on that extra large object array and check out the results. echo "<pre>" . print_r( $megaObject, true ) . "</pre>\n"; Run the script and you have a nice display of your object in a human readable format. |