PHP code example of hambrook / nestr

1. Go to this page and download the library: Download hambrook/nestr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hambrook / nestr example snippets


// need to get $array["one"]["two"]
if (array_key_exists("one", $array) && array_key_exists("two", $array["one"])) {
	$value = $array["one"]["two"];
}

// need to get $array["one"]["two"]
$value = $array->one->two();

$Nestr = new \Hambrook\Nestr\Nestr(
	[
		"foo" => "bar",
		"one" => [
			"two" => "three"
		]
	]
);

$Nestr->foo(); // note the parentheses at the end
// "bar"

$Nestr->one->two();
// "three"

$Nestr->nope->two();
// returns `null`, not an error

$value = $Nestr->nope->two("safe");
// returns "safe", not an error

$Nestr->one->four = "five";
// sets value to "five" (recursively creating levels as needed)