Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 378883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:50:16+00:00 2026-05-12T14:50:16+00:00

Ok I have ten variables but one needs to be set, but I need

  • 0

Ok I have ten variables but one needs to be set, but I need to check for each of the values until one is set. I’m doing a SWITCH/CASE statement but I’m not sure if this is the best approach because I don’t see how I can return only the variable that I need set.

$passed_var = 'A'; // Static

$var_array = getSelectedVar($passed_var);

foreach($var_array as $key => $val) {
    echo "Key: " . $key . " VALUE: " . $val . "<br />\n";
}

// How do I assign one of these values?
if(isset($var_1)) {
    echo "Var 1 Set<br />\n";
} elseif(isset($var_2)) {
    echo "Var 2 Set<br />\n";
} elseif(isset($var_3)) {
    echo "Var 3 Set<br />\n";
} elseif(isset($var_4)) {
    echo "Var 4 Set<br />\n";
} elseif(isset($var_5)) {
    echo "Var 5 Set<br />\n";
} elseif(isset($var_6)) {
    echo "Var 6 Set<br />\n";
} elseif(isset($var_7)) {
    echo "Var 7 Set<br />\n";
} elseif(isset($var_8)) {
    echo "Var 8 Set<br />\n";
} elseif(isset($var_9)) {
    echo "Var 9 Set<br />\n";
} elseif(isset($var_10)) {
    echo "Var 10 Set<br />\n";
}

function getSelectedVar($passed_var) {
    $passed_var = strtoupper($passed_var);
    $update_var = array();

    switch ($passed_var) {
        case 'A':
        case 'AB':
        case 'ABC':
        case 'ABCD':
            $update_var_1 = 1;
            $update_var = array('update_var_1'=>'1');
            break;
        case 'B':
        case 'BA':
            $update_var_2 = 1;
            $update_var = array('update_var_2'=>'1');
            break;
        case 'C':
            $update_var_3 =1;
            $update_var = array('update_var_3'=>'1');
            break;
        case 'D':
        case 'DA':
            $update_var_4 =1;
            $update_var = array('update_var_4'=>'1');
            break;
        case 'E':
            $update_var_5 =1;
            $update_var = array('update_var_5'=>'1');
            break;
        case 'F':
            $update_var_6 =1;
            $update_var = array('update_var_6'=>'1');
            break;
        case 'G':
            $update_var_7 = 1;
            $update_var = array('update_var_7'=>'1');
            break;
        case 'H':
        case 'HA':
        case 'HB':
            $update_var_8 =1;
            $update_var = array('update_var_8'=>'1');
            break;
        case 'I':
            $update_var_9 =1;
            $update_var = array('update_var_9'=>'1');
            break;
        case 'J':
        case 'JA':
            $update_var_10 =1;
            $update_var = array('update_var_10'=>'1');
            break;
        default:
            $update_var = '';
    }

    return $update_var;
}

Am I over complicating things???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:50:16+00:00Added an answer on May 12, 2026 at 2:50 pm

    I think what you need here is the $GLOBALS array. For Example, if you assign $GLOBALS[‘var_1’] = 1 then when you return from the function, the variable $var_1 will be set to 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ten buttons that each correspond to a different number. I'm looking to
I have ten values in the dataset, numbers 1 - 10 and corresponding values.
I have ten master tables and one Transaction table. In my transaction table (it
I have a jsp page which contains ten variables which I have to forward
I have ten textboxes in my winform, and i need to save the text
Suppose I have ten list item, in that case I can use both div
I have ten arrays in my application. I want to write those array values
I have ten or more(i don't know) tables that have a column named foo
I have a UIScrollView with ten UIView s in it and paging enabled. On
I have a method that's about ten lines of code. I want to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.