A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearCakePHP: How do i use Set::contains to compare subsets of Arrays to a given Array? - page 1
User InfoPosts
CakePHP: How do i use Set::contains to compare subsets of Arrays to a given Array?#1
I have the following array, named $usergrouppermissions:

Array
(
[0] => Array
(
[UserGroupPermission] => Array
(
[group_id] => 1
[permission_id] => 4
)

)

[1] => Array
(
[UserGroupPermission] => Array
(
[group_id] => 1
[permission_id] => 5
)

)

[2] => Array
(
[UserGroupPermission] => Array
(
[group_id] => 1
[permission_id] => 6
)

)

[3] => Array


[...]


In a loop, i build another array like this, named $searchme:

Array
(
[UserGroupPermission] => Array
(
[permission_id] => 1
[group_id] => 1
)

)


Now, i want to check, if given array above exists in the numeric-indexed array at the top. I currently do this:

$result = Set::contains($usergrouppermissions, $searchme);


The result is always false. Do i get something wrong here? What is the problem?

posted date: 2009-04-08 01:46:00


Re: CakePHP: How do i use Set::contains to compare subsets of Arrays to a given Array?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-08 01:46:01


Re: CakePHP: How do i use Set::contains to compare subsets of Arrays to a given Array?#3
Since PH 4.2 in_array can also use arrays as needle. So, the solution is this:in_array($searchme, $usergrouppermissions)

posted date: 2009-04-08 02:47:00


Re: CakePHP: How do i use Set::contains to compare subsets of Arrays to a given Array?#4
I know I(m very late with this answer, but here it is anyway for future generations :)The cake way would be:$exists = Set::matches ( sprintf ( (/UserGroupPermission[group_id=%s][permission_id=%s](, $searchme[(UserGroupPermission(][(group_id(], $searchme[(UserGroupPermission(][(permission_id(] ), $usergrouppermissions );If you take a look at the code of Set::contains() you will see it doesn(t work well with nested contains (at least not in your case).Set::matches() basically just calls Set::extract() with the XPath condition given and turns the result into a bool value for your pleasure.

posted date: 2009-04-13 07:16:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.