<p>This error could happen if the <code>p</code> param is set to <em>something</em>, but the value doesn’t actually contain a hyphen.</p>

<p>If you want to find out what the problematic value is, enable <a href="http://buildwithcraft.com/help/dev-mode" rel="nofollow">Dev Mode</a> and then check your browser console > <strong><code>Application Log</code></strong> > <strong><code>GET Info</code></strong> or <strong><code>POST Info</code></strong> (depending on the request type).</p>

<p>To make your code more bulletproof you can replace this line:</p>

<pre><code>{% set price = price ? price|split('-') %}
</code></pre>

<p>with:</p>

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

CC BY-SA 3.0
2015-02-20T17:08:20.997Z
Thanks, that was indeed the problem. The price param is being set to 'search' in the GET array when no value is given. How does that happen?
Jonathan Melville
CC BY-SA 3.0
2015-02-20T17:11:16.013Z
That would depend on your actual form. Can you post the rendered form HTML?
Brandon Kelly
CC BY-SA 3.0
2015-02-20T17:17:16.057Z
My search form is here. The price param has the name 'p', which is getting set to 'search' if no option is selected.
 https://gist.github.com/jonathanmelville/3f6d57b20ad0ec9220c1
Jonathan Melville
CC BY-SA 3.0
2015-02-20T17:22:58.127Z
Is there any JavaScript code being executed on this form? Nothing in that HTML would result in a `p=search` param. And Craft isn’t doing anything that would manipulate the params like that either.
Brandon Kelly
CC BY-SA 3.0
2015-02-20T17:23:58.363Z
There's no JavaScript doing anything with this form. So strange...
Jonathan Melville
CC BY-SA 3.0
2015-02-20T17:25:49.793Z
Sorry, just realized what the problem is. `p` is the GET parameter that your .htaccess redirect is assigning the URI path to. You’ll have to choose a different name for that param (both in the search form and the results page), since it’s conflicting with that.
Brandon Kelly
CC BY-SA 3.0
2015-02-20T17:00:47.013Z
2015-02-20T17:00:47.013Z
Brandon Kelly
<p>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.</p>

<p>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?</p>

<p>My search results page looks like this:</p>

<pre><code>{% 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 %}
</code></pre>

<search>
Advanced search returning 'Key "1" for array with keys "0" does not exist'
# Advanced search returning 'Key "1" for array with keys "0" does not exist'

(Asked by: username_0 on 2015-02-20)

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 %}


Search Results

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

{% if searchResults|length %}


    {% for entry in searchResults %}
    {{ entry.title }}: {{ entry.propertyPrice|currency('USD', true) }}: BR: {{ entry.bedrooms }}, BA: {{ entry.bathrooms }}
    {% endfor %}


{% else %}
No Results Found
{% endif %}

**Tags:** search

---

## 1 answers

### Answer by username_1 on 2015-02-20. Score: 2 | Accepted answer

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('-') %}

> **Comments:**
> **username_0**: Thanks, that was indeed the problem. The price param is being set to 'search' in the GET array when no value is given. How does that happen?  
> **username_1**: That would depend on your actual form. Can you post the rendered form HTML?  
> **username_0**: My search form is here. The price param has the name 'p', which is getting set to 'search' if no option is selected.  https://gist.github.com/jonathanmelville/3f6d57b20ad0ec9220c1  
> **username_1**: Is there any JavaScript code being executed on this form? Nothing in that HTML would result in a `p=search` param. And Craft isn’t doing anything that would manipulate the params like that either.  
> **username_0**: There's no JavaScript doing anything with this form. So strange...  
> **username_1**: Sorry, just realized what the problem is. `p` is the GET parameter that your .htaccess redirect is assigning the URI path to. You’ll have to choose a different name for that param (both in the search form and the results page), since it’s conflicting with that.  

---

