|
|
|
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;
}
}
?> | | |
|
| 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 | | | 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 | | | Form Submission Using Array's Categories : PHP, HTML and PHP, Beginner Guides, Arrays | | | 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 | | | CSS style switcher Categories : PHP, CSS, HTML and PHP, Arrays, Sessions | | | navbar.php3 - Dynamic hyperlinked navigation bars Categories : HTML and PHP, Arrays, PHP, Complete Programs | | | 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 | | | 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 | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | Array values from javascript to php Categories : PHP, Java Script, Arrays | |
| | | | 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;
}
}
| |
|
|
|