Advanced search returning 'Key "1" for array with keys "0" does not exist' I have an advanced search that searches real estate properties by the usual criteria: price range, Bedrooms, Bathrooms... In the form, the default is "Any" if they don't care about a particular option.

On the results page, I'm checking for a null value in case an option wasn't selected. Despite this, I'm still getting the message 'Key "1" for array with keys "0" does not exist' if the price option is missing. What is causing this?

My search results page looks like this:

{% set price = craft.request.getParam('p') %}
{% set price = price ? price|split('-') %}

{% set br = craft.request.getParam('br') %}
{% set br = br ? br %}

{% set ba = craft.request.getParam('ba') %}
{% set ba = ba ? ba %}


&lt;h1&gt;Search Results&lt;/h1&gt;

{% set searchResults = craft.entries({
    section: 'properties',
    propertyPrice: price ? ['and', '&gt;= ' ~ price[0],'&lt;= ' ~ price[1]],
    bedrooms: br ? [ 'and', '&gt;= ' ~ br ],
    bathrooms: ba ? [ 'and', '&gt;= ' ~ ba ],
    order: 'score'
}) %}

{% if searchResults|length %}

&lt;ul&gt;
    {% for entry in searchResults %}
    &lt;li&gt;{{ entry.title }}: {{ entry.propertyPrice|currency('USD', true) }}: BR: {{ entry.bedrooms }}, BA: {{ entry.bathrooms }}&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;

{% else %}
&lt;h1&gt;No Results Found&lt;/h1&gt;
{% endif %}
This error could happen if the p param is set to something, but the value doesn’t actually contain a hyphen.

If you want to find out what the problematic value is, enable Dev Mode and then check your browser console > Application Log > GET Info or POST Info (depending on the request type).

To make your code more bulletproof you can replace this line:

{% set price = price ? price|split('-') %}


with:

{% set price = (price and price matches '/-/') ? price|split('-') %}