PHP arrays - simple way to change value of relative location in deep associative array -
i have script handling array in $_session, want change 1 specific value within array. go nested foreach route, think missing simpler solution.
the branch of array want change looks like
$_session['roles'][$group][$role]['status'] = 'disabled';
this of course easy change if know $group , $role variables, script trying write want change first instance of ['status'] 'active'. (that status of first $role in first $group of $_session['roles'] array
i tried
$_session['roles'][key($_session['roles'])][key(current($_session['roles']))]['status'] = 'active';
which works, seems clumsy. missing simple function here?
there's no better solution. "relative/sequential access" , "associative arrays" don't fit anyway.
btw, depending on did array before you'll have reset() so
key()` returns first key.
edit: first part replace $_session['roles'][key($_session['roles'])]
reset($_session['roles'])
. returns first element of array. if php allows pass non-variable reset()
can same inner array, i.e. reset(reset($_session['roles']))
.
Comments
Post a Comment