PHP 代码格式化工具

专业级的 PHP 代码格式化、压缩与美化

<?php
class Example {
  public function calculateTotal($items) {
    $total = 0;
    foreach ($items as $item) {
      $total += $item['price'] * $item['quantity'];
    }

    if ($total > 1000) {
      $total = $total * 0.9; // 10% discount
    }

    $json_mock = '{"status":"success", "data": "http://example.com"}';
    return $total;
  }
}

$cartItems = [
  ['name' => 'Laptop', 'price' => 1200, 'quantity' => 1],
  ['name' => 'Mouse', 'price' => 25, 'quantity' => 2]
];

$example = new Example();
echo 'Total amount: ' . $example->calculateTotal($cartItems);