Backend Development 4 min read

Using devkeep/tools PHP Package: Installation, Utility Functions, and Example Usage

This article introduces the devkeep/tools PHP package, explains how to install it, lists its extensive utility functions for data handling, and provides concrete code examples demonstrating tasks such as array sorting, tree classification, Excel export, QR code generation, and email sending.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Using devkeep/tools PHP Package: Installation, Utility Functions, and Example Usage

During development, repetitive data handling logic can lead to duplicated code; this article introduces the open‑source devkeep/tools package for PHP, which provides a collection of utility functions to streamline such tasks.

Installation

composer require devkeep/tools

Utility functions include object‑to‑array conversion, tree categorization, multi‑dimensional array deduplication and sorting, number formatting, HTTP GET/POST requests, array‑XML conversion, zip creation/extraction, file download, email sending, Excel export, and QR code generation. The functions are accessed via devkeep\Tools\Tools::functionName() .

Example usage

// Keep two decimal places
$res = devkeep\Tools\Tools::format(100, 2);

// Multi‑dimensional array sorting
$res = devkeep\Tools\Tools::arrayMultiSort([
    ['id' => 1],
    ['id' => 2],
    ['id' => 3],
], 'id', 'desc');

// Tree classification (non‑recursive)
$res = devkeep\Tools\Tools::tree([
    ['id' => 1, 'pid' => 0, 'title' => 'title'],
    ['id' => 3, 'pid' => 1, 'title' => 'title3'],
    ['id' => 4, 'pid' => 1, 'title' => 'title4'],
]);

// Export Excel
devkeep\Tools\Tools::exportExcel(['标题','价格','重量'], [
    ['标题一','1.00','1KG'],
    ['标题二','2.00','2KG'],
], 'abc');

// Generate QR code
devkeep\Tools\Tools::qrcode('http://www.baidu.com', false, 'L', 6, 2);

// Send email
$res = devkeep\Tools\Tools::sendMail([
    'host' => 'smtp.aliyun.com',
    'port' => 465,
    'username' => '[email protected]',
    'password' => 'xxxx',
    'address' => '[email protected]',
    'title' => '测试邮件',
], [
    'mail' => '[email protected]',
    'name' => '张三',
    'subject' => '主题',
    'body' => '这是一个邮件',
]);
var_dump($res);

The article encourages readers to download the package, test it in their own projects, and adapt the code to fit their specific needs.

PHPCode Exampletoolsutility functionsdevkeep
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.