How can PHP be used to generate unique order numbers efficiently, considering the complexity of the data structure?

Generating unique order numbers efficiently in PHP can be achieved by using a combination of timestamp and a random number generator. This approach ensures uniqueness and minimizes the chances of collisions. By combining these two elements, we can create order numbers that are both unique and difficult to predict.

// Generate a unique order number
function generateOrderNumber() {
    $timestamp = time();
    $random = mt_rand(1000, 9999);
    $orderNumber = $timestamp . $random;
    
    return $orderNumber;
}

// Usage
$orderNumber = generateOrderNumber();
echo $orderNumber;