Re: Create a hierarchical hash from flat source
| From: | Simon J Welsh | Date: | Wed, 22 Jun 2011 22:17:26 +0000 |
| Subject: | Re: Create a hierarchical hash from flat source | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313663@lists.php.net to get a copy of this message | ||
On 23/06/2011, at 10:14 AM, Scott Baker wrote:
> On 06/22/2011 03:06 PM, Simon J Welsh wrote:
>> On further inspection, that's not the problem at all. The problem's around
>> assign_children($pid,$list,&$new);
>>
>> The previous line you defined $new with $new = $leaf[$pid], *copying* that node into $new.
>> Thus the assign_children() call updates $new, but not $lead[$pid].
>>
>> You can fix this by either assigning $new by reference ($new =& $leaf[$pid]) or by
>> passing a reference to $lead[$pid] to assign_children instead of $new.
>
> I updated the code:
>
> http://www.perturb.org/tmp/tree.txt
>
> I still get the same output though. Only one level of depth :(
You still need to pass the value by reference to assign_children(), so:
$new = &$leaf[$pid];
assign_children($pid,$list,&$new);
---
Simon Welsh
Admin of http://simon.geek.nz/