开发者

CakePHP Set::extract parent array based on element condition

say I have an array like this:

        [Option] => Array
            (
                [0] => Array
                    (
                        [id] => 30606
                        [option_description_id] => 1
                        [product_id] => 101512
                        [price] => 0
                        [OptionDescription] => Array
                            (
                                [id] => 1
                                [option_type_id] => 1
                                [name] => Factory
                                [short_name] => 
                                [sort_order] => 1
               开发者_运维百科                 [OptionType] => Array
                                    (
                                        [id] => 1
                                        [name] => Warranty
                                        [seo_url] => warranty
                                    )

                            )

                    )

                [1] => Array
                    (
                        [id] => 30607
                        [option_description_id] => 2
                        [product_id] => 101512
                        [price] => 44.99
                        [OptionDescription] => Array
                            (
                                [id] => 2
                                [option_type_id] => 1
                                [name] => +2 Year Extended
                                [short_name] => 
                                [sort_order] => 2
                                [OptionType] => Array
                                    (
                                        [id] => 1
                                        [name] => Warranty
                                        [seo_url] => warranty
                                    )

                            )

                    )

I want to extract the option whose OptionDescription's option_type_id ID is 1

Is there a way to do this easily with Set::extract?


Well, of course, two minutes after I post my question (after hours of trying to figure it out) I realize how easy it is.

In order to extract a parent element, you use /.. in your path syntax.

So my line for all the Options whose type_ids are 2 would be:

Set::extract('/Option/OptionDescription[option_type_id=2]/..', $product);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜