AssocArray
is a class that represents an associative array with string keys.
You can install the AssocArray
class via composer:
composer require bmt/assoc-array
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
}
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).
This project is licensed under the MIT License.