views:

43

answers:

2

I have the following array:

Array
(
    [0] => Array
        (
            [id] => 4
            [rate] => 82.50
            [pounds] => 2
            [ounces] => 3
            [mailtype] => Package
            [country] => UNITED KINGDOM (GREAT BRITAIN)
            [svccommitments] => 1 - 3 business days
            [svcdescription] => Global Express Guaranteed (GXG)
            [maxdimensions] => Max. length 46", width 35", height 46" and max. length plus girth combined 108"
            [maxweight] =>30
        )

    [1] => Array
        (
            [id] => 6
            [rate] => 82.50
            [pounds] => 2
            [ounces] => 3
            [mailtype] => Package
            [country] => UNITED KINGDOM (GREAT BRITAIN)
            [svccommitments] => 1 - 3 business days
            [svcdescription] => Global Express Guaranteed Non-Document Rectangular
            [maxdimensions] => Max. length 46", width 35", height 46" and max. length plus girth combined 108"
            [maxweight] => 70
        )

And I want to use CakePHP's Set:extract tools to filter this array on the 'maxweight', so all elements that have a 'maxweight' more than X and get an array made up of the 'rate' and 'svcdescription' fields ie:

Array (
 [82.50] => Global Express Guaranteed Non-Document Rectangular
 ...
 etc
)

Is this at all possible?

A: 

I've never used this before, but thanks for encouraging me to read up on it. Have you tried using Set::combine() ?

http://book.cakephp.org/view/662/combine

Leo
Thanks! I'm actually using this to solve a problem now.
Leo
A: 

Why can't you just use a foreach loop to process through the array.

$returnArray = array();

// Where $x is weight amount you're testing against
foreach ($yourData as $eachData) {
    if ($eachData['maxweight'] > $x) {
        $returnArray[$eachData['rate']] = $eachData['svcdescription'];
    }
}
Michael
Obviously I could, I was just thinking it could be done a different way.
unidev
There are probably a lot of ways to do it. If I could offer advice, don't get caught trying to overoptimize or spend too much time trying to find the perfect tool when a good-enough tool will do....well.... good enough. :)
Michael