[php]function array_to_pipe($array, $delimeter = '|', $parents = array(), $recursive = false) {
$result = '';
foreach ($array as $key => $value) {
$group = $parents;
array_push($group, $key);
// check if value is an array
if (is_array($value)) {
if ($merge = array_to_pipe($value, $delimeter, $group, true)) {
$result = $result . $merge;
}
continue;
}
// check if parent is defined
if (!empty($parents)) {
$result = $result . PHP_EOL . implode($delimeter, $group) . $delimeter . $value;
continue;
}
$result = $result . PHP_EOL . $key . $delimeter . $value;
}
// somehow the function outputs a new line at the beginning, we fix that
// by removing the first new line character
if (!$recursive) {
$result = substr($result, 1);
}
return $result;
}
echo '<pre>'.array_to_pipe($your_array).'</pre>';
[/php]
Revisions
- June 19, 2017 @ 05:17:06 [Current Revision] by PeterLugg
- June 19, 2017 @ 05:17:06 by PeterLugg
Revision Differences
There are no differences between the June 19, 2017 @ 05:17:06 revision and the current revision. (Maybe only post meta information was changed.)
No comments yet.