php - Is that possible to get the reference to an array from the referent of its element? -
i have php function, in 1st parameter reference array , 2nd parameter 1 of keys,
function fun(&$a, $k) { ...... } i want modify function need pass 1 parameter $a[$k]. inside function , $a can extracted $a[$k] , can call array_search($a[$k], $a) $k. possible in php?
function fun(&$ak) { // $ak $a[$k] // php utility extract $a $ak? ... $k = array_search($ak, $a); }
short answer: no, there's no way "extract" information, because information doesn't exist in scope of function.
long answer:
as people have pointed out in comments, cannot this. if have function this:
function fun(&$foo) { ... } there no information passed function $foo came from. standalone variable, array element ($bar[1]), object property ($baz->bingo), or else (think someclass::$bar->baz[$bingo->boingo]). there's no way tell.
to verify this, try var_dump($ak); in function; won't contain information array or object it's in (or array index or property name). it's other variable.
Comments
Post a Comment