<p>Just a few side notes: </p>

<ol>
<li>neither the first <code>entries</code> variable nor the second <code>entries</code> variable is an array - both are objects of kind <code>craft\elements\db\EntryQuery</code> (or <code>craft\ElementCriteriaModel</code> if it's Craft 2).</li>
<li><code>.search('nonMembers:0')</code> can be shortened to <code>nonMembers(0)</code> (or <code>"0"</code> or <code>"not 1"</code> depending on the type) and <code>search('membersExclusive:1')</code> to <code>membersExclusive(1)</code> it will increase your performance as well</li>
</ol>

<p>So far about that.. You can merge arrays in Twig via <a href="https://twig.symfony.com/doc/2.x/filters/merge.html" rel="nofollow noreferrer">|merge</a> filter</p>

<pre class="lang-twig prettyprint-override"><code>{% set values = [1, 2] %}

{% set values = values|merge(['apple', 'orange']) %}

{# values now contains [1, 2, 'apple', 'orange'] #}
</code></pre>

<hr>

<p><strong>EDIT:</strong></p>

<p>To address your case specifically, you'll need something like this...</p>

<pre><code>{% set entriesOne = craft.entries.section('publications').search('nonMembers:0').find() %}
{% set entriesTwo = craft.entries.section('improveYourClub').search('membersExclusive:1').find() %}

{% set allEntries = entriesOne|merge(entriesTwo) %}
</code></pre>

CC BY-SA 4.0
2018-08-27T17:24:51.910Z
In that case how do I merge the two objects
CreateSean
CC BY-SA 4.0
2018-08-27T17:27:14.110Z
You can't merge objects. You can only merge the results of both queries
Robin Schambach
CC BY-SA 4.0
2018-08-27T19:41:31.670Z
@CreateSean What Robin is saying is, add a `.find()` to the end of both queries. Then you'll have arrays of elements (instead of ElementCriteriaModels).
Lindsey D
CC BY-SA 4.0
2018-08-28T17:49:01.453Z
adding .find() returns a php notice with an Array to string conversion error. I had already tried that.
CreateSean
CC BY-SA 4.0
2018-08-28T21:06:54.947Z
@CreateSean Just edited Robin's answer to use your specific code... give that a shot.
Lindsey D
CC BY-SA 4.0
2018-08-30T12:14:00.093Z
@lindsey I updated the post and continue to have array to string errors.
CreateSean
CC BY-SA 4.0
2018-08-30T12:33:10.420Z
Could you maybe post your entire code? I guess the error is somewhere else
Robin Schambach
CC BY-SA 4.0
2018-08-27T16:59:46.680Z
2018-08-28T21:06:22.667Z
2018-08-28T21:06:22.667Z
Robin Schambach
<p>I have these to arrays that I need to merge into one array, but can't figure it out.</p>

<p>Please advise</p>

<pre><code>{% set entries = craft.entries.section('publications').search('nonMembers:0') %}

{% set entries = craft.entries.section('improveYourClub').search('membersExclusive:1') %}
</code></pre>

<merge><craft2>
Merging 2 Entries Array's
# Merging 2 Entries Array's

(Asked by: username_0 on 2018-08-27)

I have these to arrays that I need to merge into one array, but can't figure it out.
Please advise
{% set entries = craft.entries.section('publications').search('nonMembers:0') %}

{% set entries = craft.entries.section('improveYourClub').search('membersExclusive:1') %}

**Tags:** merge, craft2

---

## 1 answers

### Answer by username_1 on 2018-08-27. Score: 5

Just a few side notes: 

neither the first entries variable nor the second entries variable is an array - both are objects of kind craft\elements\db\EntryQuery (or craft\ElementCriteriaModel if it's Craft 2).
.search('nonMembers:0') can be shortened to nonMembers(0) (or "0" or "not 1" depending on the type) and search('membersExclusive:1') to membersExclusive(1) it will increase your performance as well

So far about that.. You can merge arrays in Twig via |merge filter
{% set values = [1, 2] %}

{% set values = values|merge(['apple', 'orange']) %}

{# values now contains [1, 2, 'apple', 'orange'] #}


EDIT:
To address your case specifically, you'll need something like this...
{% set entriesOne = craft.entries.section('publications').search('nonMembers:0').find() %}
{% set entriesTwo = craft.entries.section('improveYourClub').search('membersExclusive:1').find() %}

{% set allEntries = entriesOne|merge(entriesTwo) %}

> **Comments:**
> **username_0**: In that case how do I merge the two objects  
> **username_1**: You can't merge objects. You can only merge the results of both queries  
> **username_2**: @CreateSean What Robin is saying is, add a `.find()` to the end of both queries. Then you'll have arrays of elements (instead of ElementCriteriaModels).  
> **username_0**: adding .find() returns a php notice with an Array to string conversion error. I had already tried that.  
> **username_2**: @CreateSean Just edited Robin's answer to use your specific code... give that a shot.  
> **username_0**: @lindsey I updated the post and continue to have array to string errors.  
> **username_1**: Could you maybe post your entire code? I guess the error is somewhere else  

---

