1
I have a syntax (in php) to generate the Json file. Only that I need this syntax to be created dynamically, that is, according to the result of another class.
It’s like this:
Given the values of a Matrix
Coluna 1 - Coluna 2
190 340
190 54
Where, the data in column 1. They are the parents of the data in column 2. At line zero the value (190) is being the father of the value (340), and so on.
Given these values, the syntax would look like this:
$name = "name";
$children = "children";
$valor1 = "190";
$valor2 = "340";
$var = array ($name=>"$valor1",$children=>array(array($name=>"$valor2"),array($name=>"$ip1")));
$ip = json_encode($var, JSON_PRETTY_PRINT);
I need the syntax, which is entering the variable $var. Be created alone according to my matrix, with the amount of values it has.
For the matrix can (and will) have more lines.
Your tree has only two levels, right? (i.e. you can’t
190
father of340
and340
father of42
. Or does it? ) In other words, the number that appears in the first column will always be in level 1, and the number that appears in the second will always be in level 2, is that right? P.S. By any chance your array is sorted? This would make it a lot easier...– mgibsonbr