Remove sub arrays values automatically

Hello!

I have this pattern of an array:

array (
  0 => 
  array (
    'key1' => 'something',
    'key2' => '['i want to keep this value as final value', ['i','want','to','remove','this','array',7213,328]]',
    'key3' => NULL,
    'key4' => NULL,
  ),
  1 => 
  array (
    'key1' => 'something',
    'key2' => '['i want to keep this value as final value', ['i','want','to','remove','this','array',7213,328]]',
    'key3' => NULL,
    'key4' => NULL,
  ),

For key 2, I have multiple values. I want to keep only the first value, even a key has multiple values. All the keys will have only one value, not arrays of values. How can I get rid of them?

Thank you.

How are you getting this data in the first place? A database?

No, from request.

“from” request or FORM request? please show the code that creates this array.

I get the query from a request in Laravel Nova.

$array = $request->toQuery();

loop over the array, set key2=key2[0]