Re: [fw-general] create tree from arrays

2010-05-15 Thread shahrzad khorrami
Thankss Aleksey Zapparov :) it works grea! merc

[fw-general] create tree from arrays

2010-05-13 Thread shahrzad khorrami
hi all, I want to create an array from another array to create json file in my format and pass it to a js libraryok. I just know that I have to use recursive function... but how? it's hard for me to create the new array.. main array: Array ( [0] = Array ( [nid] = 1

[fw-general] create tree from arrays

2010-05-13 Thread Daniel Latter
Hi, Have a look at: http://www.box.net/shared/fdyp2h2yrp It includes a recursive function you could use to build your tree. Thanks Dan On 13 May 2010 10:51, shahrzad khorrami shahrzad.khorr...@gmail.com wrote: hi all, I want to create an array from another array to create json file in my

Re: [fw-general] create tree from arrays

2010-05-13 Thread Ralph Schindler
There are a couple of ways to go about buiding and recursing trees in PHP. Utilizing functions to do it is one route. The more object-oriented route would be to build a tree structure around SPL's RecursiveIterator, and RecursiveIteratorIterator. A component in Zend Framework that does this

Re: [fw-general] create tree from arrays

2010-05-13 Thread Daniel Latter
To clarify more on the link I posted, in contains a view helper that takes a flat array (with 'parentID' element), and outputs a tree. When I said function I meant on object method. Thanks On 13 May 2010 14:56, Ralph Schindler ralph.schind...@zend.com wrote: There are a couple of ways to go

Re: [fw-general] create tree from arrays

2010-05-13 Thread Aleksey Zapparov
Hello, Here's primitive variant of function you might looking for. It's very simplific and non-flexible, but it gives an idea: /** * @param array $arr Array to process * @param integer $id (optional) Base parent ID * @return array */ function mktree_array($arr, $id = 0) { $result =