I have a specific array structure that looks like this :
var items = [
[1, 0, 'Apple'],
[2, 1, 'Banana'],
[3, 0, 'Orange'],
[4, 3, 'Grape'],
[5, 0, 'Cherry'],
[6, 0, 'Mango'],
[7, 6, 'Pear'],
[8, 6, 'Coconut'],
[9, 8, 'Pineapple'],
[10, 9, 'Watermelon']];
The desired output format should be as follows:
\Apple
\Apple\Banana
\Orange
\Orange\Grape etc...
I'm attempting to modify the functionality of a PHP function like so:
function display_items($parent, $level, $array) {
$display = "";
foreach ($array as $item) {
if ($parent === $item['parentid']) {
for ($i = 0; $i < $level; $i++) {
$display .= "-";
}
$display .= " " . $item['name'] . "<br />";
$display .= display_items($item['id'], ($item + 1), $array);
}
}
return $display;
}
The goal is to replace the "-" with the full path of the items.