seffeng/laravel-helpers

PHP laravel extension helpers

v1.0.3 2024-06-12 05:08 UTC

This package is auto-updated.

Last update: 2024-12-12 06:20:37 UTC


README

安装

# 安装
$ composer require seffeng/laravel-helpers

目录说明

+---src
|   +---Commands
|   |       Crypt.php
|   +---Handlers
|   |       CacheHandler.php
|   +---Helpers
|   |       Arr.php
|   |       Json.php
|   |       Str.php
|   |       Time.php
|   |       Util.php
|   |       Xml.php
|   \---Listeners
|           QueryExecutedListener.php
+---tests
|       ArrTest.php
|       JsonTest.php
|       StrTest.php
|       TimeTest.php
|       UtilTest.php
|       XmlTest.php

示例

/**
 * TestController.php
 * 示例
 */
namespace App\Http\Controllers;

use Seffeng\LaravelHelpers\Helpers\Arr;
use Seffeng\LaravelHelpers\Helpers\Json;
use Seffeng\LaravelHelpers\Helpers\Time;
use Seffeng\ArrHelper\ReplaceArrayValue;

class TestController extends Controller
{
    public function index()
    {
        $arr = [
            'a' => [
                'b' => [
                    'c' => 'ccc'
                ]
            ],
            'd' => [
                'b' => 'ccc',
                'e' => [
                    'f' => 'hhh'
                ]
            ]
        ];
        echo '<pre>';
        var_dump(Arr::get($arr, 'a.b.c', ''));
        var_dump(Arr::getDepth($arr));
        print_r(Arr::getColumn($arr, 'b'));
        print_r($arr);
        print_r(Arr::merge($arr, [
            'd' => new ReplaceArrayValue(['hhh' => 'iii']),
            'i' => [
                'j' => 'kkk'
            ]
        ]));
        $json = Json::encode($arr);
        var_dump($json);
        print_r(Json::decode($json));
        var_dump(Time::asWeekCN(time()));
    }
}

备注

更新