PHP code example of hambrook / nest

1. Go to this page and download the library: Download hambrook/nest 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 / nest 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;

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

$value = $Nest->get("foo");
// "bar"

$value = $Nest->get(["one", "two"]);
// "three"

$value = $Nest->get(["nope", "two"]);
// returns `null`, not an error

$value = $Nest->get(["nope", "two"], "safe");
// returns "safe", not an error