Skip to content
Snippets Groups Projects
Commit b29e3015 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Mise en place de arrayDump pour faciliter l'affoichage de tableaux en console comme en HTML

parent 10e6e936
No related branches found
No related tags found
No related merge requests found
Pipeline #23023 passed
......@@ -15,6 +15,12 @@ function phpDump($php)
}
function arrayDump(array $array)
{
return \UnicaenCode\Util::arrayDump($array);
}
function javascriptDump($javascript)
{
return \UnicaenCode\Util::javascriptDump($javascript, 'jquery');
......
......@@ -143,6 +143,48 @@ class Util
public static function arrayDump(array $array, int $sub=0)
{
if (self::inConsole()){
$largestK = 0;
foreach($array as $k => $v){
if (strlen($k) > $largestK){
$largestK = strlen($k);
}
}
foreach($array as $k => $v){
echo str_pad('', $sub, ' ').str_pad($k, $largestK, ' ').' => ';
if (is_array($v)){
echo "\n";
self::arrayDump($v, $sub + 4);
}else{
var_export($v);
}
echo "\n";
}
}else{
?>
<table class="table table-condensed" style="font-size:8pt;width:auto">
<?php foreach ($array as $k => $v): ?>
<tr>
<td style="padding-bottom: 1px;padding-top: 1px;"><?= $k ?></td>
<td style="padding-bottom: 1px;padding-top: 1px;"><?php if (is_array($v)) self::arrayDump($v); else var_export($v) ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php
}
}
private static function inConsole()
{
return PHP_SAPI == 'cli';
}
public static function phpDump($php)
{
self::highlight($php, 'php');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment