Roland,
what about
:
$arraysByName['myArray'] = array();
//mak the call
myFunction(arraySliceByKey($arraysByName, 'myArray', 1));
//define the function
function myFunction($arrayOfOneArrayByName)
{
forEach($arrayOfOneArrayByName as $arrayName => $anArray) {
//your statements
}
}
function arraySliceByKey($array, $key, $length)
{
return array_slice( $array, array_search($key, array_keys($array)),
$length);
}
BTW, I could not find a function to get the index of a key in an array
(needed for array_slice).
array_search and array_keys will be slow if $arraysByName is large. The
following would be a lot faster:
function arraySliceOneByKey($array, $key)
{
return array($key => $array);
}
Greetings,
Henk Verhoeven,
www.metaclass.nl
"roland" <ro****@no-spam.org> wrote in message
news:3f**********************@news.free.fr...
But if you type $my_array you already know the name of the variable.
What is it *really* you are trying to achieve? When people ask these kinds of
questions it's almost always because they are on the wrong track.
OK, in fact, I summed up my coding pb in order not to have a too long
message.
Actually, I've got a function with the following prototype :
function my_function ($my_array);
$my_array is an array
As this function is called from different files, the array name changes.
I'd like to avoid :
function my_function ($my_array, $array_name);
I find it "dirty"...
I'd like to use the first prototype and being able to get the name of the
array $my_array in the function.
Is that clearer to you ?
thanks for your help,
--
roland