Plugin to provide filter replicating the PHP array_search function
To install Array Search, follow these steps:
- Download & unzip the file and place the
arraysearch
directory into yourcraft/plugins
directory - -OR- do a
git clone ???
directly into yourcraft/plugins
folder. You can then update it withgit pull
- -OR- install with Composer via
composer require /arraysearch
- Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
arraysearch
for Craft to see it. GitHub recently started appending-master
(the branch name) to the name of the folder for zip file downloads.
Array Search works on Craft 2.4.x and Craft 2.5.x.
A simple twig filter to return the key for a specific value within an array.
Use as per the PHP array_search function, eg
{% set colours = ['green','blue','red'] %}
{{ colours|arraySearch('red') }} // will return 2
{{ colours|arraySearch('green') }} // will return 0
Icon by IconDots
Brought to you by @cole007