WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP Click here to Update Your Picture
Stuart Cochrane
Date : May 15th 2003
Grade : 3 of 5 (graded 3 times)
Viewed : 6833
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Stuart Cochrane
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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=&gt;$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)

&lt;?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 &lt;aholmes@pureguru.com&gt;
 
function f_arr($arr) { 

    global $v;    

    $fr = "&lt;font color=red size=1&gt;"; 
    $fg = "&lt;font color=green size=1&gt;"; 
    $fb = "&lt;font color=blue size=1&gt;"; 
    $fk = "&lt;font color=black size=1&gt;"; 
    $fe = "&lt;/font&gt;"; 
    $l = "$fg [ $fe"; 
    $r = "$fg ] $fe"; 
    $a = "$fk =&gt; $fe"; 
    $out = ""; 

    foreach($arr as $k=&gt;$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("&lt;br /&gt;", $out); 
    } else { 
        return false; 
    }