Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

array path support

  • Loading branch information...
commit 8f3599ed63b4e9e73694760c551dfb4e519505a5 1 parent a2649d4
@jaz303 authored
Showing with 39 additions and 0 deletions.
  1. +39 −0 helpers.php
View
39 helpers.php
@@ -47,6 +47,45 @@ function is_enumerable($thing) {
}
//
+// Array paths (docs coming soon)
+
+function array_path_unset(&$array, $path) {
+ $tmp = & $array;
+ $path = explode('.', $path);
+ while (count($path) > 1) {
+ $key = array_shift($path);
+ if (!isset($tmp[$key])) return;
+ $tmp = & $tmp[$key];
+ }
+ unset($tmp[array_shift($path)]);
+}
+
+function array_without_path($array) {
+ $args = func_get_args();
+ array_shift($args);
+ foreach ($args as $path) array_path_unset($array, $path);
+ return $array;
+}
+
+function array_path_replace(&$array, $path, $value) {
+ $tmp = & $array;
+ $path = explode('.', $path);
+ while (count($path) > 1) {
+ $key = array_shift($path);
+ if (!isset($tmp[$key])) $tmp[$key] = array();
+ $tmp = & $tmp[$key];
+ }
+ $tmp[array_shift($path)] = $value;
+}
+
+function array_path_to_name($path) {
+ $bits = explode('.', $path);
+ $out = array_shift($bits);
+ while (count($bits)) $out .= '[' . array_shift($bits) . ']';
+ return $out;
+}
+
+//
//
function h($html, $q = ENT_QUOTES) {
Please sign in to comment.
Something went wrong with that request. Please try again.