title: generate dynamic array inside array
body: <p>I am using Laravel .if i <code>dd()</code> <code>$arrBody I</code> get following result dd($arrBody);</p>
  <pre><code>    array:7[▼
              &quot;first_name&quot; =&gt; &quot;john&quot;
              &quot;last_name&quot; =&gt; &quot;doe&quot;
              &quot;email_address&quot; =&gt; &quot;john@gmail.com&quot;,
              &quot;age&quot;=&gt; 25,
              &quot;date&quot;=&gt;&quot;2021-07-9&quot;,
              &quot;country&quot;=&gt;&quot;USA&quot;,
              &quot;code&quot;=&gt;&quot;3045&quot;
  ]
  </code></pre>
  <p>Now I want to get email,firstname and last name from $arryBody and assigned them to email,first_name and last_name key. But rest of keys like age, country,state and date i want them to go in custom_fields array but its like a hardcoded here. since I am displaying age, date,country one by one. My array may have more key/values so I want to make custom_fields array dynamic. I want field_name inside inside custom_fields to have a same name that comes after email,first_name and last_name of $arrBody array instead of manually writing field_name and want to assign that keys value to &quot;value&quot;</p>
  <pre><code>$data = [
          &quot;subscribers&quot;=&gt;[
              [
                  &quot;email&quot;=&gt; $arrBody['email'],
                  &quot;first_name&quot;=&gt; $arrBody['first_name'],
                  &quot;last_name&quot;=&gt; $arrBody['last_name'],
                  &quot;subscribed&quot;=&gt; true,
                  
                  &quot;custom_fields&quot;=&gt;[
                      [ 
                          &quot;field_name&quot;=&gt; &quot;age&quot;,
                          &quot;value_type&quot;=&gt; &quot;text&quot;,
                          &quot;value&quot;=&gt; array_key_exists('age',$arrBody) ? $arrBody['age']:''
                      ],
                      [ 
                          &quot;field_name&quot;=&gt; &quot;country&quot;,
                          &quot;value_type&quot;=&gt; &quot;text&quot;,
                          &quot;value&quot;=&gt; array_key_exists('country',$arrBody) ? $arrBody['country']:''
                      ],
                      [ 
                          &quot;field_name&quot;=&gt; &quot;date&quot;,
                          &quot;value_type&quot;=&gt; &quot;text&quot;,
                          &quot;value&quot;=&gt; array_key_exists('date',$arrBody) ? $arrBody['date']:''
                      ],
                      //so on...
                  ]
              ]
          ]
      ];
  </code></pre>
  <p>In Laravel I can use</p>
  <pre><code>$main = ['email', 'first_name', 'last_name'];
  
  $subscriber = Arr::only($arrBody, $main);
  
  $custom = Arr::exclude($arrBody, $main);
  </code></pre>
  <p>Now I want this $custom array inside  &quot;custom_fields&quot;=&gt;[] dynamically until the length of $custom array instead of checking if it has age, country etc or not.
  something like this if possible</p>
  <pre><code>custom_fields&quot; =&gt; [
                          [
                              &quot;field_name&quot; =&gt; array_keys($custom)
                              &quot;value_type&quot; =&gt; &quot;text&quot;,
                              &quot;value&quot; =&gt; array_values($custom)
                          ],
              //go until the end of $custom array
  ];
  </code></pre>