All Questions
Tagged with switch-statement php
938
questions
0
votes
0
answers
10
views
PHP, 2 different interpretations for the same evaluation using if and switch case [duplicate]
in the following code, does anyone know why is the $val === 0 case never running when there's a zero in the $arr array?
<?php
function plusMinus($arr) {
$positiveCount = $zeroCount = $...
0
votes
2
answers
124
views
loop through each value in array and then use switch statement on values [duplicate]
im new to php and i was wondering if anyone could help me.
i have an array, the values in the array are determined by another function, but the array will always be either warning, critical or ok, the ...
0
votes
0
answers
24
views
how to get session and insert data to DB then remove session
i want to insert data from the table product to the database idk how it does
otherwise i have to send it by button or form?
index.php
if(!empty($_GET["action"])) {
switch($_GET["action&...
1
vote
2
answers
42
views
PHP switch case to update array not affecting array
I'm working on developing an API integration for a small business with FedEx/UPS shipping label creators. I'm more accustomed with Python, so I've hit a few stumbling blocks with PHP, but this is the ...
0
votes
2
answers
158
views
PHP 7.3 PHP Deprecated: Function create_function() is deprecated
I updated my php vesrion from 5.6 to 7.3 and now it showing an error
PHP Deprecated: Function create_function() is deprecated in magiczoomplus/magiczoomplus.module.core.class.php on line 78
my code ...
1
vote
1
answer
36
views
Redirect Query - Header not redirecting with switch
I'm trying to redirect my links, using a php file but when I click the links nothing happens or I get a 500 error.
I've tried redirecting websites such as https://test1.org, https://test2.org and ...
0
votes
2
answers
74
views
PHP switch statement "echoing" the wrong case
$year = readline('Type your year of birth: ');
$age = 2023 - $year;
switch ($age) {
case ($age < 0):
echo 'I don't see in the future.';
break;
case ($age >= 0) && ($age ...
0
votes
1
answer
51
views
How can I be sure this local variable is set after switch statement?
I have a scenario in my code where PhpStorm alerts me that a local variable $offers may be undefined. You can find the code scenario below as well as the alert from the IDE. Is intellisense right or ...
-3
votes
1
answer
44
views
this function only adds numbers and I can not figure why?
this function only adds numbers and I can not figure why ?
function calculate($num1 , $num2 , $name = "+" )
{
switch ($name)
{
case "+" || "add" || "a&...
-6
votes
1
answer
54
views
Using Switch Statement in PHP [closed]
I have to print the multiples of numbers 3 from 80 to 100 by using switch statement
echo "Print Numbers Using Switch Statement:<br>";
for ($i=3; $i <= 100 ; $i=$i+3) {
switch (...
-1
votes
4
answers
361
views
Instantiate specific class object depending on $variable value without using conditions
I would want to write the following code without switch, if else or the ternary operator. The code is shown below:
switch (type){
case 'bed':
function create{
return new Bed($customer, $...
0
votes
1
answer
546
views
PHP- combining two params within match() expression to be set dynamically
I am trying to set two parameters within my PHP project. One is sortBy and second is orderBy..
I am trying to define the best logic for it using match() expression, available from PHP 8.0 version.
$...
1
vote
1
answer
178
views
PHP router with switch statement and regular expressions not working
I have this code in php:
$route = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
switch ($route) {
case '':
echo "root";
break;
...
0
votes
0
answers
21
views
Match dropdown menu selection to array element using iteration? PHP
Is it possible to iterate through instead of using switch statement using only PHP? I have weekdays in array, and the matching weekdays in the dropdown menu. The switch statement works, but for ...
0
votes
1
answer
81
views
looping through an array and breaking when switch statement condition is met
I am attempting to loop through an array of arrays, and for each array, I am running a function. This function has a switch statement that will alert the user if a condition is met. I want the loop to ...