# LikeCondition

> Class LikeCondition represents a LIKE condition.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [conditions](/docs/api/yii/db/conditions/index.md) › LikeCondition

| class | `yii\db\conditions\LikeCondition` |
| --- | --- |
| Extends | [`SimpleCondition`](/docs/api/yii/db/conditions/simplecondition/index.md) |
| Implements | [`ConditionInterface`](/docs/api/yii/db/conditions/conditioninterface/index.md) |
| Since | 2.0.14 |
| Source | [`framework/db/conditions/LikeCondition.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/conditions/LikeCondition.php#L19) |

Class LikeCondition represents a `LIKE` condition.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$escapingReplacements`](#property-escapingReplacements) protected | `array\|null\|false` | Map of chars to their replacements, `false` if characters should not be escaped or either `null` or empty array if escaping is condition builder responsibility. Default: `null`. | `LikeCondition` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) |  | `LikeCondition` |
| [`fromArrayDefinition()`](#method-fromArrayDefinition) static | Creates object by array-definition as described in [Query Builder – Operator format](/docs/guide/db-query-builder/index.md#operator-format) guide article. | `LikeCondition` |
| <span id="method-getColumn"></span>[`getColumn()`](/docs/api/yii/db/conditions/simplecondition/index.md#method-getColumn) |  | [`SimpleCondition`](/docs/api/yii/db/conditions/simplecondition/index.md) |
| [`getEscapingReplacements()`](#method-getEscapingReplacements) |  | `LikeCondition` |
| <span id="method-getOperator"></span>[`getOperator()`](/docs/api/yii/db/conditions/simplecondition/index.md#method-getOperator) |  | [`SimpleCondition`](/docs/api/yii/db/conditions/simplecondition/index.md) |
| <span id="method-getValue"></span>[`getValue()`](/docs/api/yii/db/conditions/simplecondition/index.md#method-getValue) |  | [`SimpleCondition`](/docs/api/yii/db/conditions/simplecondition/index.md) |
| [`setEscapingReplacements()`](#method-setEscapingReplacements) | This method allows to specify how to escape special characters in the value(s). | `LikeCondition` |

## Property details

### $escapingReplacements <span id="property-escapingReplacements"></span>

```php
protected array|null|false $escapingReplacements = null
```

Map of chars to their replacements, `false` if characters should not be escaped or either `null` or empty array if escaping is condition builder responsibility.

By default it's set to `null`.

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $column, string $operator, string[]|string $value)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$column` | `string` | The column name. |
| `$operator` | `string` | The operator to use (e.g. `LIKE`, `NOT LIKE`, `OR LIKE` or `OR NOT LIKE`) |
| `$value` | `string[]\|string` | Single value or an array of values that $column should be compared with. If it is an empty array the generated expression will  be a `false` value if operator is `LIKE` or `OR LIKE` and empty if operator is `NOT LIKE` or `OR NOT LIKE`. |

### fromArrayDefinition() <span id="method-fromArrayDefinition"></span>

```php
public static function fromArrayDefinition(mixed $operator, mixed $operands): static
```

Creates object by array-definition as described in
[Query Builder – Operator format](/docs/guide/db-query-builder/index.md#operator-format) guide article.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$operator` | `mixed` | Operator in uppercase. |
| `$operands` | `mixed` | Array of corresponding operands |

**Returns**

`static`

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if wrong number of operands have been given.

### getEscapingReplacements() <span id="method-getEscapingReplacements"></span>

```php
public function getEscapingReplacements(): array|null|false
```

**Returns**

`array|null|false`

### setEscapingReplacements() <span id="method-setEscapingReplacements"></span>

```php
public function setEscapingReplacements(array|null|false $escapingReplacements): mixed
```

This method allows to specify how to escape special characters in the value(s).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$escapingReplacements` | `array\|null\|false` | An array of mappings from the special characters to their escaped counterparts. You may use `false` to indicate the values are already escaped and no escape should be applied, or either `null` or empty array if escaping is condition builder responsibility. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters. |

**Returns**

`mixed`