PodsData::nth PHP Method

nth() public method

Fetch the nth state
Since: 2.3
public nth ( integer | string $nth ) : boolean
$nth integer | string The $nth to match on the PodsData::row_number
return boolean Whether $nth matches
    public function nth($nth)
    {
        if (empty($nth)) {
            $nth = 2;
        }
        $offset = 0;
        $negative = false;
        if ('even' == $nth) {
            $nth = 2;
        } elseif ('odd' == $nth) {
            $negative = true;
            $nth = 2;
        } elseif (false !== strpos($nth, '+')) {
            $nth = explode('+', $nth);
            if (isset($nth[1])) {
                $offset += (int) trim($nth[1]);
            }
            $nth = (int) trim($nth[0], ' n');
        } elseif (false !== strpos($nth, '-')) {
            $nth = explode('-', $nth);
            if (isset($nth[1])) {
                $offset -= (int) trim($nth[1]);
            }
            $nth = (int) trim($nth[0], ' n');
        }
        $nth = (int) $nth;
        $offset = (int) $offset;
        if (0 == $this->row_number % $nth + $offset) {
            return $negative ? false : true;
        }
        return $negative ? true : false;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Fetch the nth state
  *
  * @see PodsData::nth
  *
  * @param int|string $nth The $nth to match on the PodsData::row_number
  *
  * @return bool Whether $nth matches
  * @since 2.3
  */
 public function nth($nth = null)
 {
     $this->do_hook('nth', $nth);
     return $this->data->nth($nth);
 }