|
|
|
An alternative to print_r, this function will print an array
with HTML and Syntax highlighting. Could easily be extended to
support 3D arrays.
USAGE: echo f_arr($_SESSION);
|
<?php
function f_arr($arr) {
$fr = "<font color=red size=1>";
$fg = "<font color=green size=1>";
$fb = "<font color=blue size=1>";
$fk = "<font color=black size=1>";
$fe = "</font>";
$l = "$fg [ $fe";
$r = "$fg ] $fe";
$a = "$fk => $fe";
$out = "";
foreach($arr as $k=>$v){
$out[] = $l.$fb.$k.$fe.$r.$a.$fr.$v.$fe;
}
if(is_array($out)) {
return implode("<br />", $out);
} else {
return false;
}
}
?> | | |
|
| CSS style switcher Categories : PHP, CSS, HTML and PHP, Arrays, Sessions | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | How to pass an array from one PHP Script to another via an HTML form Categories : PHP, HTML and PHP, Arrays | | | dynamic table columns Categories : PHP, HTML and PHP, Arrays, Databases, MySQL | | | Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | Parse string to find sub-string between two arbitrary strings Categories : PHP, Strings, HTML and PHP, Arrays | | | Form Submission Using Array's Categories : PHP, HTML and PHP, Beginner Guides, Arrays | | | navbar.php3 - Dynamic hyperlinked navigation bars Categories : HTML and PHP, Arrays, PHP, Complete Programs | | | Parsing html tags with php. Get an array from this function Categories : PHP, HTML and PHP, Arrays, Tag Extractors | | | Dynamic select menu Categories : PHP, Arrays, HTML and PHP | | | This script allows people to add their favorite quotes to your website. This
could easily be modified to be a guestbook script or comment page script. Categories : PHP, Complete Programs, HTML and PHP, Misc | | | Link Submition - Allow your visitors to submit links to the site. Categories : PHP, Arrays, Filesystem, Beginner Guides | | | Produces browser-safe strings while preserving HTML tags. Categories : Strings, HTTP, PHP, HTML and PHP | |
| | | | matthew waygood wrote : 968
single dimension arrays only then.
If you called the function from within itself then it would recurrsively step through it and get the entire contents.
foreach($arr as $k=>$v){
if (isarray($v){
$out[] = "array ".$k."[".f_arr($V)."]";
} else {
$out[] = $l.$fb.$k.$fe.$r.$a.$fr.$v.$fe;
}
}
This method takes longer and more memory than just doing print_r but it gves you the formatting you require.
| | | | Aaron Holmes wrote :971
To finalize a version for printing multi-dimensional arrays you can use something like the following: (formatting may be required)
<?php
// An alternative to print_r, this function will print an array
// with HTML and Syntax highlighting. Could easily be extended to
// support 3D arrays.
// USAGE: echo f_arr($_SESSION);
// Revised for multi-dimensional arrays
// Aaron Holmes <aholmes@pureguru.com>
function f_arr($arr) {
global $v;
$fr = "<font color=red size=1>";
$fg = "<font color=green size=1>";
$fb = "<font color=blue size=1>";
$fk = "<font color=black size=1>";
$fe = "</font>";
$l = "$fg [ $fe";
$r = "$fg ] $fe";
$a = "$fk => $fe";
$out = "";
foreach($arr as $k=>$v) {
if(is_array($v)) {
$out[] = "array ".$k."[".f_arr($v)."]";
} else {
$out[] = $l.$fb.$k.$fe.$r.$a.$fr.$v.$fe;
}
}
if(is_array($out)) {
return implode("<br />", $out);
} else {
return false;
}
}
| |
|
|