ustream/arr

Ustream Array helpers

0.1.2 2013-10-21 19:19 UTC

This package is not auto-updated.

Last update: 2024-05-06 13:29:46 UTC


README

This is a collection of Array related utilities.

Extractors

Mining data from a deeply nested array is tedious. The Extractor library give a programable and composable solution to this kind of problems.

Reaching data on a simple "path" in the nested structure:

$sample = array(
  "foo" => array(
    "bar" => array(
      "baz" => "something"
    )
  )
);

$extractor = new PathExtractor(array("foo", "bar", "baz"));
$result = $extractor->extract($sample);
//        "something" # inside an Option instance

$extractor = new PathExtractor(array("foo", "bar"));
$result = $extractor->extract($sample);
//        array("baz" => "something") # inside an Option instance

$extractor = new PathExtractor(array("foo"));
$result = $extractor->extract($sample);
//        array("bar" => array("baz" => "something")) # inside an Option instance