Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

forna91fi's avatar

Query don't return null if value don't exist

I have a strange problem getting data from array. Currently I'm developing an auto translation system for some Excel file that I have

I have My database table "dictionaries" and the columns are: | it-IT | en-GB | de-DE | other languages..

I import an excel file and I group it by a reference.

For each group I need to find the text translation in the db, in this case:

I have my array:

array:67 [▼
  0 => ""
  1 => "Frase fatale non identificato"
  2 => "Indice fuori dei limiti"
  3 => "Errata configurazione del componente"
  4 => "Raggiunto il numero massimo di annidamenti"
  5 => "Id sequenza non identificata"
  6 => "Rassegnazione"
  7 => "Salto ad uno step coesistente"
  8 => "RETURN senza passare dal via"
  9 => "Da Implementare"

and then I get the translated records with:

                $b = Dictionary::whereIn($refLang, $a)
                                ->get($LangToTranslate);

Just to explain $refLang = 'it-IT and $LangToTranslate is an array with one or more languages $LangToTranslate = ['en-GB','de-DE',ect]

At this point I have two problem.

First problem: the returned collection ($b) is reversed

Second problem count($a) is 67 count($b) is 64 cause in the middle I have some string "" or missing translation in the database.

How can I get a "null result if not founded instead a smaller array??

At the moment I search for one row at time, but the result is 4783 query and 20 seconds, fortunatly is working in local host

0 likes
0 replies

Please or to participate in this conversation.