将数组值设置为大于1

时间:2016-07-30 20:50:32

标签: php arrays operators

我有阵列,$ gush。变量' you_pick'具有0-10的潜在值。我将数组$ gush传递给我的模型以从我的数据库中获取与$ gush匹配的记录。我想返回变量' you_pick'的所有记录。 = 1,2,3,4,5,6,7,8,9或10.我不希望结果变量' you_pick' = 0.现在,我已经设置了“你挑选”#39;等于1.如何设置' you_pick'在数组中大于0?或者,相反,不等于0?

    $data = array(
        'order' => 'RAND()',
        'offset' => ($pp * $page) - $pp,
        'limit' => $pp
    );

    $return = array();


    $gush = array(
        'for_dog' => 1,
        'active' => 1,
        'you_pick' => array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10')
    );


    $collars =  Collars_Model_Collar::findBy($gush, $data);

以下是模型:

public static function findBy(array $data = null, array $params = null, $_callbackQuery = null)
{
    $_callbackQuery = $_callbackQuery ? $_callbackQuery : array('Collars_Model_Collar', 'extendResult');
    if (isset($params['order']) && stripos($params['order'], 'collar.price ') !== false) {
        $p = explode(' ', $params['order']);
        $params['order'] = new JO_Db_Expr('( collar.price/(SELECT `value` FROM `currency` WHERE `code`=shop_currency LIMIT 1) ) ' . $p[1]);
    }
    $collars = parent::findBy($data, $params, $_callbackQuery);
    $collars = self::addExtraProperties($collars);
    return $collars;
}

这是更多模特的东西:

public static function findByPicks(array $data = null, array $params = null, $_callbackQuery = null)
{
    $_callbackQuery = $_callbackQuery ? $_callbackQuery : array('Collars_Model_Collar', 'extendResult');
    $collars = parent::findBy($data, $params, $_callbackQuery);
    $collars = self::addExtraProperties($collars);
    return $collars;
}


public static function extendResult($data) {

    if ($data instanceof JO_Db_Select) {
        $db = JO_Db::getDefaultAdapter();


//  a bunch of stuff

        $data->columns($rows);


//  a bunch of stuff

        $data->where('collar.active IN (0, 1, 2, 3)');

//  a bunch of stuff

        $clone = clone $data;
        $clone->reset(JO_Db_Select::COLUMNS)
                ->reset(JO_Db_Select::ORDER)
                ->reset(JO_Db_Select::LIMIT_COUNT)
                ->reset(JO_Db_Select::LIMIT_OFFSET)
                ->limit(1);

        self::$total = $db->fetchOne('SELECT COUNT(' . self::$_table . '.' . self::$_primaryKey . ') ' . $clone);
        return $data;
    }
}

1 个答案:

答案 0 :(得分:0)

通过替换
来嵌套数组     ' you_pick' => 1 同     ' you_pick' =>数组(' 1',' 2',' 3',' 4',' 5',&#39 ; 6',' 7',' 8',' 9',' 10')