0

HI
i have a form that contains checkboxes i put a variable as array and i test the values in this array

switch($pulse) {
case  $pulse[0]==1 && $pulse[1]==2:
    include('onetwonet.php');
   twonet($date,$date2,$report,$netw,$auto,$pulse,$client);
   break;
case $pulse[0]==1 && $pulse[1]==3 :
     include('onethreenet.php');
  threenet($date,$date2,$report,$netw,$auto,$pulse,$client);
   break;
case $pulse[0]==1 && $pulse[1]==4:
   include('onefournet.php');
  fournet($date,$date2,$report,$netw,$auto,$pulse,$client); 
  break;

case $pulse[0]==2 && $pulse[1]==3:
   include('twothreenet.php');
  twothreenet($date,$date2,$report,$netw,$auto,$pulse,$client);
  break;
case $pulse[0]==2 && $pulse[1]==4:
  include('twofournet.php');
  twofournet($date,$date2,$report,$netw,$auto,$pulse,$client);
break;
case $pulse[0]==3 && $pulse[1]==4:
   include('threefournet.php');
  threefournet($date,$date2,$report,$netw,$auto,$pulse,$client);
break;
case $pulse[0]==1 && $pulse[1]==2 && $pulse[1]==3:
      include('onetwothreenet.php');
     twothreenet($date,$date2,$report,$netw,$auto,$pulse,$client); 
break;

}

the line 27 does not work for me when i select 3 1,2,3 normally onetwothreenet.php is executed but it is onetwo.php who is executed..
is there a problem in my script
thanks

2
Contributors
2
Replies
16
Views
4 Years
Discussion Span
Last Post by asaidi
0

Remove all the break from the switch statment, actually when it resolves a condition it doesn't go further to check the others, read this:

It is important to understand how the switch statement is executed in order to avoid mistakes. The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don't write a break statement at the end of a case's statement list, PHP will go on executing the statements of the following case.

http://php.net/manual/it/control-structures.switch.php

A simple example:

<?php
    $a = array(
        'alpha',
        'bravo',
        'gamma'
    );

    switch($a)
    {
        case $a[0] == 'alpha' && $a[1] == 'bravo':
            echo 'first step';
        case $a[0] == 'alpha' && $a[2] == 'gamma':
            echo 'second step';
        case $a[0] == 'alpha' && $a[1] == 'bravo' && $a[2] == 'gamma':
            echo 'third step';
    }
?>

Bye!

0

Hi
thank you very much the break was the problem in my case statement

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.