<?php
/**
* pseudo print_r to string
*
* @param mixed $array
* @param mixed $flag
* @return string
*/
function printMdArrayToVar($array, $flag = 0){
foreach ($array as $k => $v) {
if (is_array($v)){
$flag += 1;
$result .= printMdArrayToVar($v, $flag);
$flag -= 1;
} else {
if (!is_array($v)){
$x=$flag;
while ($x-->0) $result .= "\t";
$result .= "[$k] $v\n";
}
}
}
return $result;
}
$aa = array("vaa1" => "aa1", "vaa2" => "aa2", "vaa3" => "aa3");
$a = array("va1" => "a1", "va2" => "a2", "vaa" => $aa);
$b = array("vb1" => "b1", "vb2" => "b2");
$c = array("vtext1" => "text1", "va" => $a, "vb" => $b, "vtext2" => "text2");
echo printMdArrayToVar($c);
?>
return →
[vtext1] text1
[va1] a1
[va2] a2
[vaa1] aa1
[vaa2] aa2
[vaa3] aa3
[vb1] b1
[vb2] b2
[vtext2] text2
Комментариев нет:
Отправить комментарий
откомментить