开发者

cakephp set class with checkboxes

开发者 https://www.devze.com 2022-12-17 20:02 出处:网络
I have an array that looks like: Array ( [63] => 0 [64] => 1 [65] => 1 [66] => 0 ) Is there a way to extract the keys for all the values that are equal to 1 (in this case I just want 64

I have an array that looks like:

Array (
    [63] => 0
    [64] => 1
    [65] => 1
    [66] => 0 )

Is there a way to extract the keys for all the values that are equal to 1 (in this case I just want 64 and 65) using Set::extract or Set::remove or some 开发者_高级运维other method?


One way may be like this:

$new_array = array();

foreach($your_array as $value)
{
  if ($value == 1)
  {
    $new_array[] = $value;
  }
}

print_r($new_array);

Or you can use the array_filter function.


Sarfrarz is right.. array_filter will be the most efficient solution.

but if you still want to use cakphp's builtin method then you should look at the manual for such things.

http://book.cakephp.org/view/640/Set

0

精彩评论

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