Advertisement
strae

Set array value with dot notation

Oct 21st, 2011
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.27 KB | None | 0 0
  1. // @ref http://stackoverflow.com/questions/7851590/array-set-value-using-dot-notation
  2. function set_value(&$arr, $path, $val)
  3. {
  4.     $loc = &$arr;
  5.     foreach(explode('.', $path) as $step)
  6.     {
  7.         if(!isset($loc[$step]))
  8.         {
  9.             $loc = &$loc[$step];
  10.         }
  11.     }
  12.     return $loc = $val;
  13. }
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement