0

I have the following Switch statement and it keeps returning "Notice: Undefined variable BB".

The variable is set and I can't work out what's wrong.

This is the first time I've studied switch and am a bit lost here, and any help will be welcome.

if ($user_has_access){
    foreach( $user_has_access as $post){    
        if ( in_array( $current_post_id, (array) $user_has_access )) {
            $bbb = 'page_member_page_id_in_user_profile_true';
        } elseif ( !in_array( $current_post_id, (array) $user_has_access )) {
            $bbb = 'page_member_page_id_in_user_profile_false';
        }
    }
 }  

switch ($bbb) :
    case "page_member_page_id_in_user_profile_true":
        echo "page_member_page_id_in_user_profile_true";
    break;

    case "page_member_page_id_in_user_profile_false":
        echo "page_member_page_id_in_user_profile_false";
    break;
                
    default:
        echo "Default hasUserProfileAccess";
    break;
endswitch;

}
John K Bell
  • 95
  • 1
  • 8
  • 1
    It's not set because `$user_has_access` is false – John Conde Feb 08 '21 at 19:51
  • You're absolutely correct @JohnConde, thank you for pointing that out. I have set bbb = 'page_member_page_id_in_user_profile_false'; now before the first if statement. Thank you! – John K Bell Feb 08 '21 at 20:57

0 Answers0