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

  • Home
  • SEARCH
  • 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 7993155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:46:01+00:00 2026-06-04T13:46:01+00:00

I got asked to write a little PHP script that takes some POSTed input

  • 0

I got asked to write a little PHP script that takes some POSTed input from a few drop down boxes which give some selectable criteria and at the end, spits out one or more string variables containing unique codes.

The variable names are of the form $thingPlaceType, and each one is unique. The drop down boxes allow for selection of:

  • either one “thing” or all “things” together
  • either one “place” or all “places” together
  • either one “type” or all “types” together

I can’t figure out how to select these codes without resorting to nested switch statements where I do

switch($_POST['thing'])
{
  case "thing1":
     switch($_POST['place'])
     {
       case "place1":
          switch($_POST['type'])
          {
            case "type1":
               $output = $thing1Place1Type1;
            case "type2":
               $output = $thing1Place1Type2;
            case "alltypes":
               $output = $thing1Place1Type1.$thing1Place1Type2.$thing1PlaceType3;
           }
        case "place2":
        ...
        case "allplaces":
        ...
      }
  case "thing2":
     switch($_POST['place'])
     {
       case "place1":
          switch($_POST['type'])
          {
            case "type1":
               $output = $thing1Place1Type1;
            ...
      ...
  ...
}

It seems that the code is turning into the Arrow Anti-Pattern. I’m thinking I could possibly do something using multi-dimensional arrays, or maybe a single array where I match the values against the keys. But I feel that’s clutching at straws and there must be something I’m missing. Is it time to turn the strings into proper objects with properties?

  • 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-06-04T13:46:03+00:00Added an answer on June 4, 2026 at 1:46 pm

    if you want to convert them to objects.. you can create this.

      class Object {
            private $thing;
            private $place;
            private $type;
    
            public function __construct() {
                $this->thing = $_POST['thing'];
                $this->place = $_POST['place'];
                $this->type  = $_POST['type'];
    
                $this->processThing($this->thing, $this->place, $this->type);
            }
    
            public function processThing($thing = false, $place = false, $type = false) {
                   //noW that you have all the properties you just need just process it
            }
    
        }
    
        if(isset($_POST['thing']) && isset($_POST['place']) && isset($_POST['type'])) {
            $object = new Object();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Convert some code from C++ to C I've got some code that
I asked some similar questions [1, 2] yesterday and got great answers, but I
I asked from few weeks ago this question: How can I teach a beginner
Sometimes I got asked on some interviews: what benefits does InnoDB have against MyISAM
I previously asked the question and got answer to Best approach to write query
This question I have asked before and just got answer that there is an
I'm looking for some advice if possible. PHP isn't the main language I write
I asked a similar question earlier here , and it got me down the
I asked a question about interfaces previously and got some excellent responses. I'm really
the other day i got an order from a customer and he asked me

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.