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

Recommended Answers

All 2 Replies

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!

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.