public static function array_assign_subkey($arr, $sKeyOrArray = 'id')
    {
        $aNew = array();

        //default option
        $c = array(
            "old_key" => "_key"
        );

        if (is_string($sKeyOrArray)) {
            $c['key'] = $sKeyOrArray;
        } elseif (is_array($sKeyOrArray)) {
            $c = array_merge($c, $sKeyOrArray);
        }

        foreach ($arr as $key => $v) {
            if (is_object($v)) {
                if (isset($v->$c['key'])) {
                    if (!isset($c['delete_old_key'])) $v->{$c['old_key']} = $key;
                    $aNew[$v->{$c['key']}] = $v;
                }
            } elseif (is_array($v)) {
                if (isset($v[$c['key']])) {
                    if (!isset($c['delete_old_key'])) $v[$c['old_key']] = $key;

                    $aNew[$v[$c['key']]] = $v;
                }
            }
        }

        return $aNew;
    }
public static function array_assign_subkey($arr, $sKeyOrArray = 'id')
    {
        $aNew = array();

        //default option
        $c = array(
            "old_key" => "_key"
        );

        if (is_string($sKeyOrArray)) {
            $c['key'] = $sKeyOrArray;
        } elseif (is_array($sKeyOrArray)) {
            $c = array_merge($c, $sKeyOrArray);
        }

        foreach ($arr as $key => $v) {
            if (is_object($v)) {
                if (isset($v->$c['key'])) {
                    if (!isset($c['delete_old_key'])) $v->{$c['old_key']} = $key;
                    $aNew[$v->{$c['key']}] = $v;
                }
            } elseif (is_array($v)) {
                if (isset($v[$c['key']])) {
                    if (!isset($c['delete_old_key'])) $v[$c['old_key']] = $key;

                    $aNew[$v[$c['key']]] = $v;
                }
            }
        }

        return $aNew;
    }
public static function array_assign_subkey ( $ arr , $ sKeyOrArray = 'id' ) { $ aNew = array ( ) ; //default option $ c = array ( "old_key" => "_key" ) ; if ( is_string ( $ sKeyOrArray ) ) { $ c [ 'key' ] = $ sKeyOrArray ; } elseif ( is_array ( $ sKeyOrArray ) ) { $ c = array_merge ( $ c , $ sKeyOrArray ) ; } foreach ( $ arr as $ key => $ v ) { if ( is_object ( $ v ) ) { if ( isset ( $ v -> $ c [ 'key' ] ) ) { if ( ! isset ( $ c [ 'delete_old_key' ] ) ) $ v -> { $ c [ 'old_key' ] } = $ key ; $ aNew [ $ v -> { $ c [ 'key' ] } ] = $ v ; } } elseif ( is_array ( $ v ) ) { if ( isset ( $ v [ $ c [ 'key' ] ] ) ) { if ( ! isset ( $ c [ 'delete_old_key' ] ) ) $ v [ $ c [ 'old_key' ] ] = $ key ; $ aNew [ $ v [ $ c [ 'key' ] ] ] = $ v ; } } } return $ aNew ; }
Array_assign_key assign the key

@param $arr
@param string $sKeyOrArray
@return array
@internal param mixed $data
Array_assign_key assign the key