tcdev/stingray

Stingray - Access array elements via dot notation

v1.0.0 2023-10-25 12:39 UTC

This package is auto-updated.

Last update: 2024-10-25 17:08:16 UTC


README

Stingray - Access array elements via dot notation

Installing via Composer

Add Stingray to your project:

$>  composer.phar require projectmeta/stingray *

or directly to composer.json:

{
    "require": {
        "projectmeta/stingray": "*"
    }
}

Then update your dependencies:

$>  composer.phar update

Example Usage

To get any node from an array:

<?php

//Some file needing access to array nodes

use projectmeta\Stingray\Stingray;

$stingray = new Stingray();

$someArray = array(
    'node_lvl1' => array(
        'node_lvl2' = array(
            'node_lvl3a' => true,
            'node_lvl3b' => false,
            'node_lvl3c' => array()
            )
        )
    )
);

$nodeAlias = 'node_lvl1.node_lvl2.node_lvl3a';

$newValue = false;

// return true
$stingray->get($someArray, $nodeAlias);

// change true to false
$stingray->set($someArray, $nodeAlias, $newValue);