Re: Thinking out loud - a continuation...
| From: | Robert Cummings | Date: | Tue, 27 Mar 2012 05:21:10 +0000 |
| Subject: | Re: Thinking out loud - a continuation... | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317289@lists.php.net to get a copy of this message | ||
On 12-03-26 07:05 PM, Jay Blanchard wrote:
[snip] On Mar 26, 2012, at 5:58 PM, Robert Cummings wrote:I think you need two things... the recursive post processor that removes the string indexes for the children. And then a function that creates a JavaScript array expression from an object or array. The question I have for you... is given the following array structure that might be generated from my previous code: <?php array (On 12-03-26 06:52 PM, Jay Blanchard wrote:[/snip] I'm listening - so could this be added to the code that you just wrote? Or do I need to recurse the output from json_encode()?[snip]They are arrays... but JSON_encode is creating objects. You can create arrays by traversing the array structure recursively and outputing your own JavaScript code to build a JavaScript array. I don't know if that would serve the purpose, but you would end up with an array.Did you end up with a satisfactory output? It's not overly difficult to generate an array instead of an object.[/snip] I did for all but this one instance. Are you saying that it would be easy to make of the children arrays? I thought they were already - am I missing something?
'exec-001' => array
(
'name' => 'exec-001',
'children' => array
(
'sub-exec-011' => array
(
'name' => 'sub-exec-011',
'children' => array
(
'sub-sub-exec-111' => array
(
'name' => 'sub-sub-exec-111',
'children' => array()
),
'sub-sub-exec-112' => array
(
'name' => 'sub-sub-exec-112',
'children' => array()
)
)
),
'sub-exec-012' => array
(
'name' => 'sub-exec-012',
'children' => array
(
'sub-sub-exec-121' => array
(
'name' => 'sub-sub-exec-121',
'children' => array()
),
'sub-sub-exec-122' => array
(
'name' => 'sub-sub-exec-122',
'children' => array()
)
)
)
)
),
'exec-002' => array
(
'name' => 'exec-002',
'children' => array
(
'sub-exec-021' => array
(
'name' => 'sub-exec-021',
'children' => array
(
'sub-sub-exec-211' => array
(
'name' => 'sub-sub-exec-211',
'children' => array()
),
'sub-sub-exec-212' => array
(
'name' => 'sub-sub-exec-212',
'children' => array()
)
)
),
'sub-exec-022' => array
(
'name' => 'sub-exec-022',
'children' => array
(
'sub-sub-exec-221' => array
(
'name' => 'sub-sub-exec-221',
'children' => array()
),
'sub-sub-exec-222' => array
(
'name' => 'sub-sub-exec-222',
'children' => array()
)
)
)
)
)
);
?>
On first blush, I think you want the following structure (from your recent posts):
<?php
array
(
0 => array
(
'name' => 'exec-001',
'children' => array
(
0 => array
(
'name' => 'sub-exec-011',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-111',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-112',
'children' => array()
)
)
),
1 => array
(
'name' => 'sub-exec-012',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-121',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-122',
'children' => array()
)
)
)
)
),
1 => array
(
'name' => 'exec-002',
'children' => array
(
0 => array
(
'name' => 'sub-exec-021',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-211',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-212',
'children' => array()
)
)
),
1 => array
(
'name' => 'sub-exec-022',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-221',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-222',
'children' => array()
)
)
)
)
)
);
?>
Essentially, entries at the root and entries for the children are just auto indexed array items but the actual entries in those arrays retain the associative index structure for retrieval of the specific information. let me know and I can probably whip you up something.
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.