PHP code example of doloto / big0nia

1. Go to this page and download the library: Download doloto/big0nia library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

doloto / big0nia example snippets


foreach ($users as $user) {
    foreach ($orders as $order) {
        if ($user->getId() === $order->getUserId()) {
            // ...
        }
    }
}

$result = [];
foreach ($items as $item) {
    $result = array_merge($result, [$item]);
}

foreach ($items as $item) {
    usort($data, $cmp);
    // ... use $data ...
}

foreach ($users as $user) {
    if (in_array($user->getId(), $bannedIds)) {
        // ...
    }
}

class UserService {
    public function __construct(private OrderMatcher $matcher) {}

    public function process(array $users): void {
        foreach ($users as $user) {
            $this->matcher->matchAll($user);
        }
    }
}

class OrderMatcher {
    public function matchAll($user): void {
        foreach ($this->orders() as $order) {
            if ($user->getId() === $order->getUserId()) {
                // ...
            }
        }
    }

    private function orders(): array {
        return [];
    }
}

tests/Analysis/data/array-merge-in-loop.php:17
  Potential O(n²) algorithm: array_merge() rebuilds $result from scratch
  on every iteration.
  Tip: Replace array_merge($result, [...]) with $result[] = ... (or an
  equivalent append), or build the pieces separately and merge once after
  the loop.