Undefined array key “text” warning [closed]

I’m trying to solve the issue of Undefined array key “text”, but implemented fix doesn’t seem to work. Any ideas? 🙁 The whole file is fairly big, thousands of line, wondering if that’s part of the issue but error is same line always

ORIGINAL

  static function _helper_to_panel_values() {
        // add the rest
        foreach (self::get_all() as $id => $config) {
            $buffy_array[] = array(
                'text' => $config['text'],
                'title' => '',
                'val' => $id,
                'img' => $config['img']
            );
        }

        // the first template is the default one, ex: it has no value in the database
        $buffy_array[0]['val'] = '';

        return $buffy_array;
    }

TRYING TO FIX

static function _helper_to_panel_values() {
    $buffy_array = array(); // Initialize the array to avoid undefined variable warning

    // add the rest
    foreach (self::get_all() as $id => $config) {
        // Check if 'text' key exists in $config array before accessing it
        $text = isset($config['text']) ? $config['text'] : '';
        $img = isset($config['img']) ? $config['img'] : '';
        
        $buffy_array[] = array(
            'text' => $text,
            'title' => '',
            'val' => $id,
            'img' => $img
        );
    }

    // the first template is the default one, ex: it has no value in the database
    $buffy_array[0]['val'] = '';

    return $buffy_array;
}