Category: PHP

  • Yii2 类级别的事件(Class-Level Event Handlers)

    文件结构 Structure ├── … ├── components │ └── SampleEventComponent.php ├── config │ └── web.php ├── controllers │ └── SiteController.php ├── events │ ├── BaseEvent.php │ ├── SampleEvent.php │ └── TestEvent.php ├── interfaces │ └── EventInterface.php └── yii 启动 Bootstrap create SampleEventComponent and load when app bootstrapped. // config/web.php $config = [ … 'bootstrap' => ['log',…

  • Nested JSON Validation in Laravel / Lumen

    Nested JSON Validation in Laravel / Lumen

    我们可能会提交这样一个请求,一个 嵌套的 JSON 对象,那么如何对 JSON 对象的那边元素进行验证呢? ### Save Post Comments POST {{API_BASE_URL}}/module/v1/posts/2/comments Content-Type: application/json Accept: application/json Authorization: Bearer {{TOKEN}} { "data": [ { "media_ids": [1,2,3], "title": "Title A", "status": "A", "comment": "Objectively seize progressive ROI before unique bandwidth." }, { "media_ids": [4,5,6], "title": "Title B", "status": "B", "comment": "Objectively mesh sticky value for global data.…

  • Retrieve a value from a deeply nested array using “dot” notation
  • PHP 冒泡算法

    没什么用,写了玩玩的。 function bubble_sort(array $items): array { for ($i = 0; $i < count($items); $i++) { for ($j = $i + 1; $j < count($items); $j++) { if ($items[$i] > $items[$j]) { $temp = $items[$i]; $items[$i] = $items[$j]; $items[$j] = $temp; } } } return $items; } print_r(bubble_sort([5, 3, 1, 2, 7]));

  • 递归 (JavaScript && PHP)

    递归 (JavaScript && PHP)

    编程语言中,函数Func(Type a,……)直接或间接调用函数本身,则该函数称为递归函数。递归函数不能定义为内联函数。