woutvw/nested-object
最新稳定版本:v1.0.0
Composer 安装命令:
composer require woutvw/nested-object
包简介
A PHP class that allows creating nested objects with the flexibility of JSON but the advantages of PHP classes.
README 文档
README
A PHP class that allows you to create nested objects with the flexibility of JSON objects, but with the advantages of PHP classes.
Installation
Install the package via Composer:
composer require woutvw/nested-object
Usage
This class allows you to dynamically create nested objects without predefined structures, similar to working with JSON in JavaScript, but maintaining the advantages of PHP.
Creating a Nested Object
You can create an object with nested properties like this:
use WoutVW\NestedObject; // Initialize with data $data = [ 'user' => [ 'name' => 'John Doe', 'email' => 'john@example.com' ], 'status' => 'active' ]; $object = new NestedObject($data); // Access nested properties echo $object->user->name; // Outputs 'John Doe' // Set new properties $object->user->age = 30;
Setting values
You can assign new values just like a regular object:
$object->user->city = 'New York';
Converting to an Array
You can convert the nested object back to an array using the toArray() method:
$array = $object->toArray(); print_r($array);
License
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-26