In Array

Last updated on
20 November 2022

This condition relies on the php's in_array() function.

If the value or property is a scalar, this condition behaves exactly like the equals condition.

Available configuration keys:

  • value: (one of value or property is required) The literal array in which to search for the source.

  • property: (one of value or property is required) The source or destination property key to 'get' and then search for the source.

  • strict: (optional) 'strict' parameter for in_array(). Defaults to FALSE.

  • negate: (optional) Whether to negate the 'in_array' condition. Defaults to FALSE. You can also negate the 'in_array' plugin by using 'not:in_array' as the plugin id.

  • source: (optional) Property or array of properties on which to evaluate the condition. If not set, the condition will be evaluated on the source passed to the ::evaluate() method, typically the source of the process plugin that is using this condition.

Examples

1. Skip row if the source_field is 'one', 'two', or 'three'

process:
  skip_one_two_three:
    plugin: skip_on_condition
    source: source_field
    condition:
      plugin: in_array
      value:
        - one
        - two
        - three
      strict: true
   method: row
   message: 'That was one, two, or three'

2. Evaluate whether source_value is found within the source_array

process:
  array_contains_value:
    plugin: evaluate_condition
    source: source_field
    condition:
      plugin: in_array
      property: source_array

3. Remove a set of ids from a source array.

process:
  array_without_1_or_2:
    plugin: filter_on_condition
    source: source_ids
    condition:
      plugin: not:in_array
      value:
        - 1
        - 2
      string: true

Help improve this page

Page status: No known problems

You can: