-1

Function result is not expected. I would like json encode type records

function aTree($array, $treeList)
{

    foreach ($array as $key => $value) {

        if (is_array($value) && !empty($value)) {
            $valueX = ltrim($value["link"]["link_x"], "node/");
            $valueY = $value["link"]["link_y"];

            echo array_push($value, $valueX, $valueY);
            if (!empty($value["below"])) {
                echo "------\n";
                aTree($value["below"]);
                echo "------\n\n";
            }
        }
    }

}

I expect results

[{"link_x":"link_y"},{"link_x":"link_y"} ... ]
Ömer
  • 121
  • 1
  • 4
  • 19
  • It is unclear what you ask, please give an example input array for us to understand... And the documentation of `array_push()` clearly states that the return value is a integer, I doubt you want to cho` that: http://php.net/manual/en/function.array-push.php – arkascha Sep 08 '15 at 12:22

1 Answers1

0

Call

array_push($value, array($valueX => $valueY));

instead of

echo array_push($value, $valueX, $valueY);

and finally (after your foreach loop) you have to call

echo json_encode($value);
mario.van.zadel
  • 2,919
  • 14
  • 23