Voting

: min(three, eight)?
(Example: nine)

The Note You're Voting On

Matthew Ruivo (mruivo at gmail)
18 years ago
For those of you needing to print an array within a buffer callback function, I've created this quick function. It simply returns the array as a readable string rather than printing it. You can even choose whether to return it in normal text-mode or HTML. It's recursive, so multi-dimensial arrays are supported. I hope someone finds this useful!

<?php

function return_array($array, $html = false, $level = 0) {
$space = $html ? "&nbsp;" : " ";
$newline = $html ? "<br />" : "\n";
for (
$i = 1; $i <= 6; $i++) {
$spaces .= $space;
}
$tabs = $spaces;
for (
$i = 1; $i <= $level; $i++) {
$tabs .= $spaces;
}
$output = "Array" . $newline . $newline;
foreach(
$array as $key => $value) {
if (
is_array($value)) {
$level++;
$value = return_array($value, $html, $level);
$level--;
}
$output .= $tabs . "[" . $key . "] => " . $value . $newline;
}
return
$output;
}

?>

<< Back to user notes page

To Top