Continue inserting data from multiples arrays even if one of them is empty

I’m creating a kind of multilingual dictionary with words from different languages on the same row with php, mysql and laravel. I insert the data from arrays with different length with a for loop. My problem is that the loop will stop as soon as one of the arrays is empty. I’d like to continue inserting data as long as all the arrays aren’t empty, even if it means that some columns will be NULL in the database.

$words = request()->json()->all();
$base_words = array_column($words, 'baseForm');
$fr = array_column($words, 'fr');
$en = array_column($words, 'en');
$es = array_column($words, 'es');
$it = array_column($words, 'it');
$de = array_column($words, 'de');

for ($i = 0; $i < max($fr, $en, $es, $it, $de); $i++) {
  Word::insert([
    'ru' => $base_words[$i],
    'fr' => $fr[$i],
    'en' => $en[$i],
    'es' => $es[$i],
    'it' => $it[$i],
    'de' => $de[$i]
  ]);
}

Here is how my $words array looks like with dd() (I deleted some entries or the array would have been to long).

array:56 [
  0 => array:2 [
    "baseForm" => "да"
    "es" => "sí"
  ]
  1 => array:2 [
    "baseForm" => "да"
    "es" => "y"
  ]
  15 => array:2 [
    "baseForm" => "да"
    "it" => "e"
  ]
  20 => array:2 [
    "baseForm" => "да"
    "fr" => "oui"
  ]
  28 => array:2 [
    "baseForm" => "да"
    "en" => "yes"
  ]
  29 => array:2 [
    "baseForm" => "да"
    "en" => "yeah"
  ]
]

Thanks in advance to anyone who would like to help me on this.

EDIT: Here comes the full working code for people that it could interest :

    $words = request()->json()->all();
    $base_words = array_column($words, 'baseForm');
    $declined_words = array_column($words, 'declinedForm');
    $fr = array_column($words, 'fr');
    $en = array_column($words, 'en');
    $es = array_column($words, 'es');
    $it = array_column($words, 'it');
    $de = array_column($words, 'de');

    for ($i = 0; $i < count(max($fr, $en, $es, $it, $de)); $i++) {
      Word::insert([
        'ru' => isset($base_words[$i]) ? $base_words[$i] : null,
        'fr' => isset($fr[$i]) ? $fr[$i] : null,
        'en' => isset($en[$i]) ? $en[$i] : null,
        'es' => isset($es[$i]) ? $es[$i] : null,
        'it' => isset($it[$i]) ? $it[$i] : null,
        'de' => isset($de[$i]) ? $de[$i] : null
      ]);
      }

EDIT: new JSON structure

{
  "жаловаться": [
      {
        "word": "se plaindre",
        "lang": "fr"
      },
      {
        "word": "se lamenter",
        "lang": "fr"
      },
      {
        "word": "gémir",
        "lang": "fr"
      },
      {
        "word": "se désoler",
        "lang": "fr"
      }
  ]
}

Answer

I will assume that your insert breaks because you’re not having the same number of elements in all arrays.

So if you had 4 elements in the array1 but 7 in the array2, when you try to access array1[5], it would break.

You can try with the following:

$words = request()->json()->all();
$base_words = array_column($words, 'baseForm');
$fr = array_column($words, 'fr');
$en = array_column($words, 'en');
$es = array_column($words, 'es');
$it = array_column($words, 'it');
$de = array_column($words, 'de');

for ($i = 0; $i < max($fr, $en, $es, $it, $de); $i++) {
  Word::insert([
    'ru' => isset($base_words[$i]) ? $base_words[$i] : null,
    'fr' => isset($fr[$i]) ? $fr[$i] : null,
    'en' => isset($en[$i]) ? $en[$i] : null,
    'es' => isset($es[$i]) ? $es[$i] : null,
    'it' => isset($it[$i]) ? $it[$i] : null,
    'de' => isset($de[$i]) ? $de[$i] : null
  ]);
} 

Or provide the complete error.