Sunday, December 27, 2009

RE: Sort 2 arrays into 1

Thanks for your response.

I ended up going with:

Set::sort($selections, '{n}.Skill.name', 'asc');


Dave

-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of peterchenadded
Sent: December-28-09 12:00 AM
To: CakePHP
Subject: Re: Sort 2 arrays into 1

See code below...

<?php

function cmp($a, $b) {
$a = $a['Skill']['name'];
$b = $b['Skill']['name'];

if($a == $b) return 0;
return ($a < $b) ? -1 : 1;
}

$a = array(
0 => array(
'Skill' => array(
'name' => 'Peter'
)
),
1 => array(
'Skill' => array(
'name' => 'Alla'
)
),
2 => array(
'Skill' => array(
'name' => 'Wu'
)
)
);

print_r($a);

usort($a, 'cmp');
echo '<br />';

print_r($a);
?>

Check out the new CakePHP Questions site http://cakeqs.org and help others
with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com To
unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group
cake-php+at http://groups.google.com/group/cake-php?hl=en
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.722 / Virus Database: 270.14.114/2575 - Release Date: 12/27/09
05:48:00

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: