sykesssem/array-object

PHP 数组对象

1.0.0-a 2021-09-12 23:36 UTC

This package is auto-updated.

Last update: 2024-09-13 06:19:50 UTC


README

在PHP中创建类型化和面向对象的数组

安装

使用Composer通过以下命令安装此包

composer require sikessem/array-object

用法

示例代码

<?php

use SIKessEm\ArrayObject\{
  function map,
  Type
};

require_once $COMPOSER_AUTOLOAD_FILE; // Replace $COMPOSER_AUTOLOAD_FILE by the path of your vendor autoload

$array = [
  // ... Describe your array
];

$object1 = new class {
  // ... Describe your first object
};

$object2 = new class {
  // ... Describe your second object
};


/*
 * Your can use all PHP var types :
 * - Boolean
 * - Integer
 * - Double
 * - String
 * - Array
 * - Object
 * - Resource
 */
$map_array_object = map(Type::ARRAY, Type::OBJECT); // Create a new map of type [array => object]
$map_array_object->set($array, $object1); // Add a new association between $array and $object1
$map_array_object->set($array, $object2); // Set the old association of $array with $object2
$object = $map_array_object->get($array); // Get the object associated with $array into $object
print_r();

作者

SIGUI Kessé Emmanuel (https://sikessem.com/) <opensource@sikessem.com> | GitLab | GitHub | npm | Composer - Packagist | Twitter

安全报告

请将任何敏感问题发送到 report@sikessem.com。谢谢!