Ichier » coding » ichier's coding corner
{ php }  
  echo_var
date 2004
update 2006
code <?php
function echo_var(&$var,$dump=false) {
    if (!
is_array($var)&&!is_object($var)) { echo '<br>'var_dump($var); return; }
    if(
$dump) { echo '<pre>'var_dump($var); echo '</pre>'; }
    else { echo 
'<pre>'print_r($var); echo '</pre>'; }
}
?>
description my most needed function :)
prints a complete array readable or the type and value of a variable
because the variable is passed by reference you can't print a value directly
syntax <?php
echo_var
(mixed var [, bool dump]);
?>
explanation set bool true if you want use dump instead of print_r on arrays, theres nothing to tell, just include it to your project and check what you need to know...
some examples:
<?php
echo_var
($var);
$var false;
echo_var($var);
$var 2;
echo_var($var);
$var 2.76;
echo_var($var);
$var 'Hallo';
echo_var($var);
$var '';
echo_var($var);
$var 0;
echo_var($var);
$var = array('lala','lolo','ha'=>'ho','ha'=>array('a'=>'Aa','b'=>'Bb','123',456),'Niko',42);
echo_var($var);
$var = array('lala','ha'=>array('a'=>'Aa',456),'Niko');
echo_var($var,true);
?>


echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 72
NULL
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 74
boolean FALSE
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 76
integer 2
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 78
double 2.76
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 80
string (5) Hallo
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 82
string (0)
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 84
integer 0
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 86
array (5) Array ( [0] => lala [1] => lolo [ha] => Array ( [a] => Aa [b] => Bb [0] => 123 [1] => 456 ) [2] => Niko [3] => 42 )
echo_var() called in /ichier/htdocs/ACMS/inc/build_page.php(124) : eval()'d code on line 88
array(3) { [0]=> string(4) "lala" ["ha"]=> array(2) { ["a"]=> string(2) "Aa" [0]=> int(456) } [1]=> string(4) "Niko" }