4
I’m developing a PHP application that needs to display a graphical indicator. The problem is that the data comes from an external API and depending on the filter applied, the API does not return me points that I need to insert into the chart.
Example:
// Chama a API sem filtros
$dados = $api->get()->limit(6);
var_dump($dados);
// Retorna
'metaPontual' =>
array (size=6)
3 => float 178036332.62
4 => float 176975684.39
5 => float 173823421.06
6 => float 170114093.13
7 => float 168775993.4
8 => float 167259382.68
// Aplicando um filtro
$dadosFiltrado = $api->get(['nome' => 'Lucas'])->limit(6);
var_dump($dadosFiltrado);
// O Array Não retorna todos os pontos.
'metaPontual' =>
array (size=6)
1 => float 183635670.39
4 => float 176975684.39
5 => float 173823421.06
6 => float 170114093.13
8 => float 167259382.68
9 => float 167259382.68
I need a routine that acts in order to create a "LEFT JOIN" between array 1 and array 2, remembering that arrays are examples, the keys returned by arrays are different, so that:
$arrayFinal = array_left_join(array_keys($dados), $dadosFiltrado);
var_dump($array_final)
'metaPontual' =>
array (size=6)
3 => null
4 => float 176975684.39
5 => float 173823421.06
6 => float 170114093.13
7 => null
8 => float 167259382.68
Would be a
array_merge
that you are seeking?– bfavaretto
Vc wants a new array with the values they both have in common?
– rray
@bfavaretto would not be a merge array because I only need the values that both have in common plus the keys of the first array.
– gmsantos
The keys that only exist in the second are left out so?
– bfavaretto
Man, there’s no function ready, but play a little with some
foreach
solves your problem. I eventually do this, but no time to respond now– Emerson Rocha
@bfaretto exactly, which only exists in the second array I should disregard.
– gmsantos
@Emersonrochaluiz I also thought of using a
foreach
but if possible I would like to avoid its use for reasons of attachment (http://www.phpbench.com/). I’ll run some performance tests with some variations of the code I posted.– gmsantos