Skip to content

Tag: switch-statement

php- switch fails before i select an option

I’m having a problem with php switch function. I know it must be simple, but i’m just learning and I can’t seem to find the right way to code it. This is the issue: It works fine when you click any of the options, but it sends an error msg when I first load up the page… Now, I suppose

How to use a Function of Switch/Case, if at all?

I have various products inside a database, each has its own price, the pattern to output a product price is: $product[i][“price”] I also have various “product types”, which are manually defined in my code, each with index number that will relate to each product accordingly: I want to e…

Switch multiple case statement

Can someone suggest me how can I replace the below code? How do I rewrite the code in order to avoid the repetition of the block case 3:{code block A; break;}? How can I have combined code for case 1 and case 3? Answer This format is shown in the PHP docs: EDIT 04/19/2021: With the release of PHP8 and