Skip to content

Instantly share code, notes, and snippets.

@gravataLonga
Last active April 28, 2017 19:30
Show Gist options
  • Select an option

  • Save gravataLonga/ae7c1e98bd645d46b7d9 to your computer and use it in GitHub Desktop.

Select an option

Save gravataLonga/ae7c1e98bd645d46b7d9 to your computer and use it in GitHub Desktop.
output cli function
<?php
function output ( $str, $tabs = 0, $date = TRUE, $silent = FALSE )
{
// Silent echo's
if( !empty($silent))
{
return FALSE;
}
if( is_array($str))
{
foreach ($str as $k => $v)
{
if( !is_array($v))
{
output( $k . ' => ' . $v, $tabs );
}else{
output( $k . ' => (', $tabs);
output($v, $tabs+1);
output(" )", $tabs);
}
}
}else{
$tab_ascii = (chr(9));
if(empty($date))
{
$date = date('Y-m-d H:i:s');
echo '[ ' . $date . '] :: ';
}
if( $tabs > 0)
{
for( $n = $tabs; $n>0; $n--)
{
echo $tab_ascii;
}
}
echo $str . PHP_EOL;
}
}
?>
@gravataLonga
Copy link
Copy Markdown
Author

In your php use:

<?php
require_once "output.php";
output(array("ola","ola 1", "ola 2" => array('1','2','a','b' => array(array(1,2,3,4),array(5,6,7,8)))));
?>

Output:

0 => ola
1 => ola 1
ola 2 => (
0 => 1
1 => 2
2 => a
b => (
    0 => (
        0 => 1
        1 => 2
        2 => 3
        3 => 4
     )
    1 => (
        0 => 5
        1 => 6
        2 => 7
        3 => 8
     )
 )
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment