tr Skip to content
Black Friday FlowMattic for life, 12 payments of $33.25 Or $399 once. Nothing added for splitting Ends in --Days --Hrs --Min --Sec See the deal

PHP Array Functions Without Code: Sort, Filter and Search Lists

FlowMattic PHP Array module: a list from an API is sorted, filtered or de-duplicated in one step and the top item is sent on to Slack.

Lists turn up everywhere in automation: order line items, tags from a form, rows from an API, a column of email addresses pasted into a textarea. The PHP Array module in FlowMattic gives you 16 ready-made PHP array functions as a workflow step, so you can count, search, filter, sort and de-duplicate that data without writing a line of code.

It is for anyone whose workflow receives a list and needs one item, a cleaner list or a different shape before the next app will accept it. Each action returns plain fields you can map, plus a status so you can branch on the result. Here is every one of the PHP array functions, what it needs and what it returns.

What is the PHP Array module?

PHP Array by FlowMattic is a built-in action app whose purpose, in the builder’s words, is to “Perform array functions on the array data in your workflow”. You add it like any other step in the visual workflow builder, pick an action, and point it at JSON data from the trigger or an earlier step. It sits with the other data tools in the app picker.

How PHP array functions work in a workflow

  1. Add a step and choose PHP Array by FlowMattic.
  2. Pick one of the 16 actions.
  3. Map the list into the JSON Data field (some actions call it Array, or take a plain list instead).
  4. Fill in the action’s own fields, such as Filter Key and Filter Value.
  5. Test the step and map the output fields into the steps that follow.
FlowMattic workflow builder showing the PHP Array by FlowMattic step with the Filter Array by Key and Value action, JSON Data, Filter Key and Filter Value fields.
The PHP Array step set to Filter Array by Key and Value, keeping only the items whose priority is urgent.

All 16 actions

ActionFieldsWhat you get back
Get Value by IndexJSON Data, Array Index(es)The item at an index, starting from 0. Comma-separated indexes such as 1,3 return several.
Get Array CountJSON Datacount of items
Array SearchJSON Data, Array Search TermThe key where the value was found, including inside nested items
Convert List to ArrayList of Values, SeparatorAn array; the separator defaults to a comma
Convert Array to ListArray, SeparatorA list joined by the separator
Insert Value at IndexArray, Array Index, Value to InsertThe updated_array
New Line to ArrayNew Line Separated Listoriginal_array and an iterator_array of list_item objects
Extract JSON DataJSON Data to ExtractEach key as its own field; nested objects become fields such as customer_name, while lists of objects stay as JSON
Itemize ArrayJSON DataAn items list, one item per entry
Create Line ItemsLine Items (key and value rows)line_items built from comma-separated values, each with an fm_item_index
Get Array Item by Key and ValueJSON Data, Search Key, Search ValueThe first matching item, up to 4 levels deep, as json_item plus its fields
Get Array Item by ValueJSON Data, Search ValueThe first item containing the value in any field, up to 4 levels deep
Filter Array by Key and ValueJSON Data, Filter Key, Filter Valuefiltered_array and its count
Remove Array Item by Key and ValueJSON Data, Key, Valueupdated_array, removed_count, remaining_count
Sort Array by KeyJSON Data, Sort Key, Sort Ordersorted_array, Ascending (A-Z, 0-9) or Descending (Z-A, 9-0)
Remove DuplicatesJSON Data, Deduplication Key (Optional)unique_array, removed_items and the counts

Sort Array by Key compares numbers as numbers when both values are numeric, and text in natural, case-insensitive order otherwise. Remove Duplicates without a key drops exact duplicate items; with a key such as email, it keeps the first item for each value.

Use cases

Tag a contact from a comma-separated form field

A form sends interests as “seo, email, ads”. Convert the list to an array and loop through it to apply one CRM tag per interest.

Form submission → PHP Array (Convert List to Array) → Iterator → CRM: add tag

Invite a pasted list of people

An operations lead pastes email addresses one per line. New Line to Array trims each line, drops repeats and returns an iterator_array ready for a loop that sends each invite.

Webhook → PHP Array (New Line to Array) → Iterator → Send email

Pick the top result from an API

A pricing API returns offers in no particular order. Sort by price ascending, then take index 0 to get the cheapest offer for a WooCommerce note or a Slack alert.

API request → PHP Array (Sort Array by Key) → PHP Array (Get Value by Index) → Slack

Clean an import before it hits your table

A partner sends a lead file with repeats. Remove Duplicates by email and import only unique_array; the removed_items output tells you who was skipped.

Webhook → PHP Array (Remove Duplicates) → Iterator → WP Tables: new record

Route support tickets by what is inside them

Filter a list of ticket items by priority equal to urgent and use Get Array Count on the result. A Router sends the run to the on-call channel only when the count is above zero.

Scheduler → API request → PHP Array (Filter Array by Key and Value) → Router

Build invoice lines from parallel fields

An order form sends product as “Hosting, Domain” and price as “120, 15”. Create Line Items pairs them into item_1 and item_2, ready for a PDF invoice.

Form submission → PHP Array (Create Line Items) → PDF Template → Email

Look up one record in an AI agent’s output

An AI step returns a JSON list of companies with scores. Get Array Item by Key and Value finds the entry where domain matches the lead, so you can write that score to the CRM.

AI Agent → PHP Array (Get Array Item by Key and Value) → CRM: update contact

Tips and gotchas

  • Give it real JSON. If the JSON Data field does not hold a valid array, the step stops with “Invalid JSON format.” rather than guessing. Check the mapped field in the test output first.
  • Indexes start at 0. The first item is index 0, the second is index 1.
  • Insert Value at Index needs an existing index. To insert at position 3, the array must already have an item at 3; otherwise the step returns “Index not found”.
  • Matches are exact. Filter, Remove and Get by Key and Value compare values as exact strings (your key and value are trimmed first), so Urgent and urgent differ.
  • A value of 0 counts as empty. Filter Array, Remove Array Item and Get Array Item by Key and Value reject a match value of 0 as missing. Match on another field, or use a PHP Functions step.
  • New Line to Array de-duplicates. Repeated lines are removed and each line is trimmed, so don’t use it where the number of repeats matters.
  • Outputs are often JSON strings. Arrays such as filtered_array come back as JSON text, which the Iterator and the JSON Parser read directly.

Related features

  • Iterator: run steps once for each item the PHP Array step returns.
  • JSON Parser: read single values from objects and build new ones.
  • Router: send the run down a different path based on a count or a match.

FAQ

Do I need to know PHP to use the PHP Array module?

No. The PHP array functions are named actions with labelled fields. You pick the action, map your data and test it. If you do want custom logic, the PHP Functions step is there too.

How do I loop through an array in FlowMattic?

Shape the list with a PHP Array action such as New Line to Array or Itemize Array, then pass the result to the Iterator module. The steps inside the loop run once per item.

How do I convert an array to a comma-separated string?

Use Convert Array to List. Map the array into the Array field and set a separator; leave it empty for a comma. The joined text arrives as list.

Can I remove duplicate rows by one field?

Yes. Remove Duplicates takes an optional Deduplication Key. Set it to email, for example, and only the first item for each email address is kept.

PHP Array ships with FlowMattic as a built-in module, next to nearly 900 integrations. Compare the plans and put your lists into shape inside the workflow.

More from the blog