Thanks for the suggestions guys.
I will look into cake Set classes.
maybe i should have explained it further....
Im using cake as a backend to extjs and need the output of the findall
result to be json format. This is the reason i wanted the array in
that format. What i would like better is to use cake powerful array
output and then find out how to use that in the extjs json reader?
That would be perfect. failing that i will have to reformat the
findall result into a structure that extjs json reader can use.
I am stronger with cake than extjs and json, i guess thats why I
started looking for a cake answer to the problem.
Any extjs bakers out there?
cheers,
Trav.
On Apr 11, 9:52 pm, grigri <[EMAIL PROTECTED]> wrote:
> I can't seem to work out a one-liner that doesn't involve lambda
> functions, but this is the "easiest" I came up with:
>
> foreach ($users as $idx => $user) {
> $users[$idx] = call_user_func_array('array_merge',
> array_values($user));
>
> }
>
> I do agree though, only use this if you really need it. Cake's normal
> data arrays are easy to deal with once you get used to them.
>
> On Apr 11, 12:33 pm, Adam Royle <[EMAIL PROTECTED]> wrote:
>
> > the_woodsman is right - if you can cope with Cake's array structure
> > then your app will be more consistent, however there are times when
> > you do need the data in a certain format, and plain php can cope with
> > this easily. I'm not sure how the Set class can do this easily and as
> > quick as the following.
>
> > $users2 = array();
> > foreach ($users as $user) {
> > $users2[] = array(
> > 'id' => $user['Users']['id'],
> > 'name' => $user['Users']['name'],
> > 'total_cost' => $user[0]['total_cost'],
> > 'descr' => $user['group']['descr']
> > );}
>
> > $users = $users2;
>
> > // or for php5
>
> > foreach ($users as &$user) {
> > $user = array(
> > 'id' => $user['Users']['id'],
> > 'name' => $user['Users']['name'],
> > 'total_cost' => $user[0]['total_cost'],
> > 'descr' => $user['group']['descr']
> > );
>
> > }
>
> > On Apr 11, 8:56 pm, the_woodsman <[EMAIL PROTECTED]> wrote:
>
> > > I believe Cake's Set class is used for manipulating arrays in fairly
> > > complex ways, and might be useful in this situation-
>
> > >http://www.thinkingphp.org/2007/02/24/cake-12s-set-class-eats-arrays-...
>
> > > However, make sure you really *need* the data in this format, rather
> > > than are just doing it out of force of habit - you get a lot more out
> > > of Cake if you go with its conventions rather than against them!
>
> > > On Apr 11, 11:38 am, trav <[EMAIL PROTECTED]> wrote:
>
> > > > hi bakers!
>
> > > > Im not sure if this is a cake question or more just a general php
> > > > question.
>
> > > > When i create a database view that includes some calculations and i
> > > > perform a findAll against that view cake give the following output:
>
> > > > Array
> > > > (
> > > > [0] => Array
> > > > (
> > > > [Users] => Array
> > > > (
> > > > [id] => 1
> > > > [name] => 'jane'
> > > > )
>
> > > > [0] => Array
> > > > (
> > > > [total_cost] => 400
> > > > )
> > > > [group] => Array
> > > > (
> > > > [descr] => 'public'
> > > > )
> > > > )
>
> > > > I really need the following output:
>
> > > > Array (
> > > > [id] => 1
> > > > [name] => 'jane'
> > > > [total_cost] => 400
> > > > [descr] => 'public'
> > > > )
>
> > > > Can cake help me out here or am i left to code a solution in php?
>
> > > > Cheers,
> > > > Trav.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---