codeies/json-query

PHP 类,用于在 JSON 数据上执行类似 MySQL 的查询。

v1.0.0 2024-03-27 13:06 UTC

This package is auto-updated.

Last update: 2024-09-29 13:38:19 UTC


README

JsonQuery 是一个 PHP 类,允许您对 JSON 数据执行类似于 MySQL 查询的操作,包括搜索、排序和分页。

安装

您可以通过将 JsonQuery 添加为依赖项到您的 composer.json 文件,使用 Composer 安装 JsonQuery。

composer require codeies/json-query

使用方法

require_once 'vendor/autoload.php';

use Codeies\JsonQuery\JsonQuery;

// Create a new instance of JsonQuery
$jsonQuery = new JsonQuery('path/to/your/data.json');

// Find method
$results = $jsonQuery->find('searchValue')
                    ->sort('category', 'desc')
                    ->paginate($page, $perPage)
                    ->getData();

方法

find($value)
Searches for the specified value within the JSON data.

sort($key, $order = 'asc')
Sorts the filtered data by the specified key and order.

paginate($page, $perPage)
Paginates the filtered data based on the specified page number and items per page.

getData()
Returns the filtered and paginated data.
[
    {"id": 1, "name": "Product 1", "category": "Category A", "price": 10.99},
    {"id": 2, "name": "Product 2", "category": "Category B", "price": 20.99},
    ...
]

许可证

本项目采用 MIT 许可证 - 详细信息请参阅 LICENSE 文件。确保将 'path/to/your/data.json' 替换为您的 JSON 数据文件的实际路径,并更新任何占位符为您的实际项目详情。

README.md 文件提供了对您的包的简要概述,如何使用 Composer 安装它的说明,使用示例,可用方法的详细信息,示例数据格式以及有关许可证的信息。

// 输出结果

print_r($results);