1

Is there a limit to the number of elements and/or their length in the array passed into the WHEREIN eloquent method? For example:

$skuChunks = array_chunk($skus, 20);
foreach ($skuChunks as $chunk) {
    BCProduct::whereIn('sku', $chunk)->update(['flag' => $flagValue]);
}

What is the biggest number that I can use instead of 20? If the length of the SKU is 10 symbols, would that affect the number of elements ($chunk size) in comparison if the length was 5 symbols?

Thanks

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • PHP use a memory_limit specified in php.ini. Mysql use [max_allowed_packet] (https://stackoverflow.com/questions/4275640/mysql-in-condition-limit/4275704) – Alex Alvarado Jan 28 '22 at 16:53
  • Does this answer your question? [MySQL number of items within "in clause"](https://stackoverflow.com/questions/1532366/mysql-number-of-items-within-in-clause) – steven7mwesigwa Jan 28 '22 at 17:29

2 Answers2

0

you can slice array when send in whereIn with this method

array_slice($array, 0, 5) // return the first five elements
0
$skuChunks = array_chunk($skus, 20);
foreach ($skuChunks as $chunk) {
    BCProduct::whereIn('sku', $chunk)->update(['flag' => $flagValue]);
}

I think you have to make a condition to be sure that sku is not too much, so a condition that checks if sku is not greater than 20

jarlh
  • 42,561
  • 8
  • 45
  • 63
Nagini
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 29 '22 at 04:24