WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 4 of 5 (graded 6 times)
Viewed : 19502
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  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;
    }
}
?>



Parse string to find sub-string between two arbitrary strings
Categories : PHP, Strings, HTML and PHP, Arrays
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
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
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
Dynamic select menu
Categories : PHP, Arrays, HTML and PHP
Parsing html tags with php. Get an array from this function
Categories : PHP, HTML and PHP, Arrays, Tag Extractors
navbar.php3 - Dynamic hyperlinked navigation bars
Categories : HTML and PHP, Arrays, PHP, Complete Programs
CSS style switcher
Categories : PHP, CSS, HTML and PHP, Arrays, Sessions
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
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
PHP MultiList Mailing List Manager
Categories : Email, HTML and PHP, PHP
function textwrap will wrap text to any desired width using <BR>\n as the default line break. Default wrap width is 80 columns.
Categories : Strings, HTML and PHP, PHP
How to use regular expressions to get the list of links from an HTML page
Categories : PHP, Regexps, HTML, 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=&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; 
    }