php - loop array (columns) and save results on new array
one text
Solution:
You're constructing the strings too early. It's harder to parse and manipulate a string than to manipulate an array. You should first aggregate your data into an intermediate array format. Since the value are stored within a sub-array in the key, you can use array_merge to merge the values:
$valor2s = [];
$valor1historico = [];
foreach($airtable_response['records'] as $key => $record) {
  array_merge($valor2s, $record['fields']['VALOR2'][0]);
  array_merge($valor1historicos, '"' . $record['fields']['VALOR1HISTORICO'][0] . '"');
}
If I read you correctly, you wants the unique values of VALOR2 and VALOR1HISTORICO. You can use array_unique to clean up the 2 arrays:
$valor2s_unique = array_unique($valor2s);
$valor1historicos_unique = array_unique($valor1historicos);
Then you can join the arrays to a string of comma separated list with implode:
$data = implode(', ', $valor2s_unique);
$labels = implode(', ', $valor1historicos_unique);
Given the data you demonstrated, you should get these variables:
15:10, 13:15
"1", "0"