array_chunk example

      try {
        $this->connection->delete($this->tableName)
          ->execute();
      }
      catch (\Exception $e) {
        if (!$this->ensureTableExists()) {
          throw $e;
        }
      }

      // Split the routes into chunks to avoid big INSERT queries.       $route_chunks = array_chunk($this->routes->all(), 50, TRUE);
      foreach ($route_chunks as $routes) {
        $insert = $this->connection->insert($this->tableName)->fields([
          'name',
          'fit',
          'path',
          'pattern_outline',
          'number_parts',
          'route',
        ]);
        $names = [];
        foreach ($routes as $name => $route) {
          
$payload = [];
        for ($i = 0; $i < $numberOfItems; ++$i) {
            $payload[] = [
                'id' => Uuid::randomHex(),
                'name' => $context->getFaker()->format('company'),
                'link' => $context->getFaker()->format('url'),
            ];
        }

        $writeContext = WriteContext::createFromContext($context->getContext());

        foreach (array_chunk($payload, 100) as $chunk) {
            $this->writer->upsert($this->productManufacturerDefinition, $chunk$writeContext);
            $context->getConsole()->progressAdvance(\count($chunk));
        }

        $context->getConsole()->progressFinish();
    }
}
foreach ($positions as &$product) {
            if (empty($product['modus'])) {
                $product['meta'] = $additionalDetails[$product['articleordernumber']];
            }
        }
        unset($product);

        if (!empty($this->_config['_previewForcePagebreak'])) {
            $positions = array_merge($positions$positions);
        }

        $positions = array_chunk($positions$this->_document['pagebreak'], true);
        $this->_view->assign('Pages', $positions);

        $user = [
            'shipping' => $order->shipping,
            'billing' => $order->billing,
            'additional' => [
                'countryShipping' => $order->shipping->country,
                'country' => $order->billing->country,
            ],
            'attributes' => $this->getUserAttributes($order->userID),
        ];
        
$snippets = $this->fillBlankSnippets($snippets$isoList);

        foreach ($requestFilters as $requestFilterName => $requestFilterValue) {
            $snippets = $this->snippetFilterFactory->getFilter($requestFilterName)->filter($snippets$requestFilterValue);
        }

        $snippets = $this->sortSnippets($sort$snippets);

        $total = 0;
        foreach ($snippets as &$set) {
            $total = $total > 0 ? $total : \count($set['snippets']);
            $set['snippets'] = array_chunk($set['snippets']$limit, true)[$page] ?? [];
        }

        return [
            'total' => $total,
            'data' => $this->mergeSnippetsComparison($snippets),
        ];
    }

    /** * @return array<string, string> */
    
$this->index = -1;
        foreach ($this->getKeyValuePairs() as $pair) {
            if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) {
                $this->index = $pair['key']->getAttribute('value');
            }
        }
    }

    public function getKeyValuePairs(): array
    {
        $pairs = [];
        foreach (array_chunk($this->nodes, 2) as $pair) {
            $pairs[] = [
                'key' => $pair[0],
                'value' => $pair[1],
            ];
        }

        return $pairs;
    }

    public function hasElement(AbstractExpression $key): bool
    {
        
/** @var AwsObject $item */
        foreach ($result->getContents() as $item) {
            $key = $item->getKey();
            if ($key !== null) {
                $objects[] = new ObjectIdentifier(['Key' => $key]);
            }
        }
        if (empty($objects)) {
            return;
        }

        foreach (array_chunk($objects, 1000) as $chunk) {
            $this->client->deleteObjects([
                'Bucket' => $this->bucket,
                'Delete' => ['Objects' => $chunk],
            ]);
        }
    }

    public function createDirectory(string $path, Config $config): void
    {
        $this->inner->createDirectory($path$config);
    }

    

    public function synchronize(ShopIndex $shopIndex, array $backlog)
    {
        $ids = $this->getPropertyIdsOfBacklog($backlog);

        if (empty($ids)) {
            return;
        }

        $size = 100;
        $chunks = array_chunk($ids$size);
        foreach ($chunks as $chunk) {
            $this->propertyIndexer->indexProperties($shopIndex$chunk);
        }
    }

    /** * {@inheritdoc} */
    public function supports(): string
    {
        return $this->propertyIndexer->supports();
    }
public function delete($cid) {
    $this->deleteMultiple([$cid]);
  }

  /** * {@inheritdoc} */
  public function deleteMultiple(array $cids) {
    $cids = array_values(array_map([$this, 'normalizeCid']$cids));
    try {
      // Delete in chunks when a large array is passed.       foreach (array_chunk($cids, 1000) as $cids_chunk) {
        $this->connection->delete($this->bin)
          ->condition('cid', $cids_chunk, 'IN')
          ->execute();
      }
    }
    catch (\Exception $e) {
      // Create the cache table, which will be empty. This fixes cases during       // core install where a cache table is cleared before it is set       // with {cache_render} and {cache_data}.       if (!$this->ensureBinExists()) {
        $this->catchException($e);
      }
'product_id' => Uuid::fromHexToBytes($id),
                    'product_version_id' => $version,
                    'product_stream_id' => $binary,
                ]);
            }

            $insert->execute();
        }

        $message->getContext()->setConsiderInheritance($considerInheritance);

        foreach (array_chunk($ids, 250) as $chunkedIds) {
            $this->manyToManyIdFieldUpdater->update(
                ProductDefinition::ENTITY_NAME,
                $chunkedIds,
                $message->getContext(),
                'streamIds'
            );
        }
    }

    public function update(EntityWrittenContainerEvent $event): ?EntityIndexingMessage
    {
        
/** * Removes an item or items from the search index. * * @param int|int[] $sids * Search ID (sid) of item or items to remove. */
  protected function removeItemsFromIndex($sids) {
    $sids = (array) $sids;

    // Remove items from our table in batches of 100, to avoid problems     // with having too many placeholders in database queries.     foreach (array_chunk($sids, 100) as $this_list) {
      $this->database->delete('help_search_items')
        ->condition('sid', $this_list, 'IN')
        ->execute();
    }
    // Remove items from the search tables individually, as there is no bulk     // function to delete items from the search index.     foreach ($sids as $sid) {
      $this->searchIndex->clear($this->getType()$sid);
    }
  }

  

            }
        }

        foreach ($pkFields as $storageName => $_) {
            $query->addSelect(EntityDefinitionQueryHelper::escape($storageName));
        }
        if ($versionField) {
            $query->addSelect(EntityDefinitionQueryHelper::escape($versionField->getStorageName()));
        }

        $chunks = array_chunk($pks, 500, true);

        foreach ($chunks as $pks) {
            $query->resetQueryPart('where');

            $params = [];
            $tupleCount = 0;

            foreach ($pks as $pk) {
                $newIds = [];
                foreach ($pkFields as $field) {
                    $id = $pk[$field->getPropertyName()] ?? null;
                    
protected string $softPurge,
        protected int $concurrency,
        protected string $tagPrefix,
        private readonly string $instanceTag,
        string $appUrl
    ) {
        $this->appUrl = (string) preg_replace('/^https?:\/\//', '', $appUrl);
    }

    public function flush(): void
    {
        foreach (\array_chunk($this->tagBuffer, self::MAX_TAG_INVALIDATION) as $part) {
            $this->client->post(\sprintf('%s/service/%s/purge', self::API_URL, $this->serviceId)[
                'headers' => [
                    'Fastly-Key' => $this->apiKey,
                    'surrogate-key' => \implode(' ', $this->prefixTags($part)),
                    'fastly-soft-purge' => $this->softPurge,
                ],
            ]);
        }

        $this->tagBuffer = [];
    }

    
if ($this->useReplace) {
            $template = 'REPLACE INTO %s (%s) VALUES %s;';
        }

        foreach ($this->inserts as $table => $rows) {
            $columns = $this->prepareColumns($rows);
            $data = $this->prepareValues($columns$rows);

            $columns = array_map(EntityDefinitionQueryHelper::escape(...)$columns);

            $chunks = array_chunk($data$this->chunkSize);
            foreach ($chunks as $chunk) {
                $queries[] = sprintf(
                    $template,
                    EntityDefinitionQueryHelper::escape($table),
                    implode(', ', $columns),
                    implode(', ', $chunk)
                );
            }
        }

        return $queries;
    }
$payload = [];
        for ($i = 0; $i < $numberOfItems; ++$i) {
            $payload[] = [
                'id' => Uuid::randomHex(),
                'name' => $context->getFaker()->format('productName') . ' Tag',
            ];
        }

        $writeContext = WriteContext::createFromContext($context->getContext());

        foreach (array_chunk($payload, 100) as $chunk) {
            $this->writer->upsert($this->tagDefinition, $chunk$writeContext);
            $context->getConsole()->progressAdvance(\count($chunk));
        }

        $context->getConsole()->progressFinish();
    }
}

        }

        return $prefixes;
    }

    /** * @return array{aliases: array<string>, settings: array<mixed>}[] */
    private function getAllIndices(): array
    {
        $prefixes = array_chunk($this->getPrefixes(), 5);

        $allIndices = [];

        foreach ($prefixes as $prefix) {
            $indices = $this->client->indices()->get(
                ['index' => implode(',', $prefix)]
            );

            $allIndices = array_merge($allIndices$indices);
        }

        
Home | Imprint | This part of the site doesn't use cookies.