1

I am trying to go to the admin panel of my codeigniter project but. I am facing an error. which is Trying to access array offset on value of type bool

on view file --

<?php 
$report_list = get_ci_value("reports_list");
if( count((array)$report_list) == 1){
    foreach ((array)$report_list as $row){
            $id = strtolower( str_replace(" ", "_", $row['name']) );//the error is showing on this line
        if(!segment(3) == $id){
            redirect( get_module_url("index/".$id) );
        }
    }
}
?>

controller--

foreach ($tab_groups as $tab => $data) {

            foreach ($data as $main => $row) {
                
                if( isset( $row['sub_menu'] ) ){
                    usort( $row['sub_menu'] , function($a, $b) {
                        return $a['position'] <=> $b['position'];
                    });

                    $menu_groups[$tab][$main] = $row;             
                }else{
                    $menu_groups[$tab][$main] = $row;
                }

            }

        }

        if(isset($menu_groups[2])){
            $CI->reports_list = $menu_groups[2];
        }else{
            $CI->reports_list = false;
        }

I already tried this but it's not working. then another error comes- Undefined variable: id

if( is_array($row) ) {
    $id = strtolower( str_replace(" ", "_", $row['name']) );
}

How can I solve this problem Trying to access array offset on value of type bool ? I am using php 7.4.11

16_018_RHR
  • 425
  • 3
  • 10
  • 2
    In the end of your question, you have a solution to the issue in your title. The new error (undefined variable) probably stems from the fact that you only define `$id` in case `$row` is an array. If your code further down uses `$id` while `$row` wasn't an array, then you'll get that error. Just put the code after that uses `$id` inside the same `if`-statement. Then you'll know it's always defined. – M. Eriksson Sep 04 '22 at 08:39

0 Answers0