Skip to content
Advertisement

dump returned values as expanded array in laravel

I am using dump($value) function. I have an associative array with lots of entries in it. I need to see the values right away without having to click the expansion button when dumped. I can use var_dump() to see it right away but I like it more using dump because it is modern and interactive. Below is the snapshot of dump function:

enter image description here

Advertisement

Answer

Here’s a quick format tool, no need to use laravel: (Source)

$pretty = function($v='',$c="&nbsp;&nbsp;&nbsp;&nbsp;",$in=-1,$k=null)use(&$pretty){$r='';if(in_array(gettype($v),array('object','array'))){$r.=($in!=-1?str_repeat($c,$in):'').(is_null($k)?'':"$k: ").'<br>';foreach($v as $sk=>$vl){$r.=$pretty($vl,$c,$in+1,$sk).'<br>';}}else{$r.=($in!=-1?str_repeat($c,$in):'').(is_null($k)?'':"$k: ").(is_null($v)?'&lt;NULL&gt;':"<strong>$v</strong>");}return$r;};

echo $pretty($array);

Here’s a screenshot of sample output, as well. (Bonus points for figuring out what the data is) screenshot of output

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement