<p>You would need to join the array into a string, like so:</p>

<pre><code>// Begin defining the response data for this entry
$data = [
    'title' =&gt; $entry-&gt;title,
    'slug' =&gt; $entry-&gt;url,
    'status' =&gt; $entry-&gt;status,
    'textArea' =&gt; implode(' ',$bodyBlocks)
]; 
</code></pre>

CC BY-SA 4.0
2019-08-19T13:44:11.460Z
2019-08-19T13:44:11.460Z
Udo
<p>I am trying to create an array <code>bodyBlocks</code> by looping through all of my matrix fields called <code>blockTextContent</code>:</p>

<pre><code>$bodyBlocks = [];
foreach ($entry-&gt;getFieldValue('pageBuilder')-&gt;all() as $block){
    switch ($block-&gt;type-&gt;handle) {
        case 'blockText':               
            $bodyBlocks[] = $block-&gt;blockTextContent;
            break;
        }
    }

// Begin defining the response data for this entry
$data = [
    'title' =&gt; $entry-&gt;title,
    'slug' =&gt; $entry-&gt;url,
    'status' =&gt; $entry-&gt;status,
    'textArea' =&gt; $bodyBlocks
];  
</code></pre>

<p>The JSON response is as below, focusing on the <code>textArea</code> line. </p>

<pre><code>"title": "Title Here",
"slug": "slug-here",
"status": "live",
"textArea": [
    "&lt;p&gt;Text from first 1st block&lt;/p&gt;",
    "&lt;p&gt;Text from first 2nd block&lt;/p&gt;",
    "&lt;p&gt;Text from first 3rd block&lt;/p&gt;",
],
"heroBanner": "img.jpg",
</code></pre>

<p>The above is working as expected, cool. BUT I'd like the response to appear as below. Merging that matrix field in to one line in <code>textArea</code>, so without the separating quotation marks and surrounding square brackets [ ]? </p>

<p>My desired response would look like this in the end:</p>

<pre><code>"title": "Title Here",
"slug": "slug-here",
"status": "live",
"textArea": "&lt;p&gt;Text from first 1st block&lt;/p&gt; &lt;p&gt;Text from first 2nd block&lt;/p&gt; &lt;p&gt;Text from first 3rd block&lt;/p&gt;",
"heroBanner": "img.jpg",
</code></pre>

<p>Thanks!</p>

<plugin-elementapi><elementquery><element>
Array from matrix fields without quotations
# Array from matrix fields without quotations

(Asked by: username_0 on 2019-08-19)

I am trying to create an array bodyBlocks by looping through all of my matrix fields called blockTextContent:
$bodyBlocks = [];
foreach ($entry->getFieldValue('pageBuilder')->all() as $block){
    switch ($block->type->handle) {
        case 'blockText':               
            $bodyBlocks[] = $block->blockTextContent;
            break;
        }
    }

// Begin defining the response data for this entry
$data = [
    'title' => $entry->title,
    'slug' => $entry->url,
    'status' => $entry->status,
    'textArea' => $bodyBlocks
];  

The JSON response is as below, focusing on the textArea line. 
"title": "Title Here",
"slug": "slug-here",
"status": "live",
"textArea": [
    "Text from first 1st block",
    "Text from first 2nd block",
    "Text from first 3rd block",
],
"heroBanner": "img.jpg",

The above is working as expected, cool. BUT I'd like the response to appear as below. Merging that matrix field in to one line in textArea, so without the separating quotation marks and surrounding square brackets [ ]? 
My desired response would look like this in the end:
"title": "Title Here",
"slug": "slug-here",
"status": "live",
"textArea": "Text from first 1st block Text from first 2nd block Text from first 3rd block",
"heroBanner": "img.jpg",

Thanks!

**Tags:** plugin-elementapi, elementquery, element

---

## 1 answers

### Answer by username_1 on 2019-08-19. Score: 1 | Accepted answer

You would need to join the array into a string, like so:
// Begin defining the response data for this entry
$data = [
    'title' => $entry->title,
    'slug' => $entry->url,
    'status' => $entry->status,
    'textArea' => implode(' ',$bodyBlocks)
];


---

