Re: changing values deep in an array by reference, with some index vars in array..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ah, comments for
http://www.php.net/manual/en/language.references.return.php show:

-----------------------------------------------------------------------------
 php at thunder-2000 dot com
02-Feb-2007 10:31
If you want to get a part of an array to manipulate, you can use this function

function &getArrayField(&$array,$path) {
  if (!empty($path)) {
    if (empty($array[$path[0]])) return NULL;
    else return getArrayField($array[$path[0]], array_slice($path, 1));
  } else {
    return $array;
  }
}

Use it like this:

$partArray =& getArrayField($GLOBALS,array("config","modul1"));

You can manipulate $partArray and the changes are also made with $GLOBALS.
-----------------------------------------------------------------------------



On Thu, Mar 11, 2010 at 9:35 AM, Rene Veerman <rene7705@xxxxxxxxx> wrote:
> Hi..
>
> I've got a db-insert command array that's several levels deep..
> Let's abstract this as:
> $wm[$idx1][$idx2][$idx3][..etc] //$WorkMemory
>
> Several of my helper functions need to work on the "original,
> top-call_level" $wm.
> So i pass it as &$wm, and have the helper function declarations accept
> it as such aswell.
>
> Some of the $idxN vars are in an array $pathToDBcmd ($idx3, $idx4,
> ...) in some of the helper functions.
>
> Now i need to change a variable deep in the original, top-call_level
> $wm, but with some of the required indexes in $pathToDBcmd..
>
> I can't use something like
> $wm[$idx1][$idx2][$pathToDBcmd[0]][$pathToDBcmd[1]] because i dont
> know what count($pathToDBcmd) is..
>
> Tips will be much appreciated..
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux