bmt / assoc-array
Represents an associative array with string keys.
v1.0.0
2023-05-31 16:56 UTC
This package is not auto-updated.
Last update: 2024-12-12 22:15:58 UTC
README
AssocArray
is a class that represents an associative array with string keys.
Installation
You can install the AssocArray
class via composer:
composer require bmt/assoc-array
Usage
To use the AssocArray
class, you can follow these steps:
- Create an instance of
AssocArray
by passing an associative array with string keys:
$data = ['id' => 5656, 'name' => 'jhon']; $array = new AssocArray($data);
- Access values in the associative array using array access syntax:
$id = $array['id']; $name = $array['name'];
- Check if a specific offset exists:
if (isset($array['id'])) { // Offset exists } else { // Offset does not exist }
Exceptions
The AssocArray
class throws the following exceptions:
InvalidArgumentException
if the array structure is invalid.RuntimeException
if you try to set or unset a value (read-only).
License
This project is licensed under the MIT License.