Welcome Guest, Not a member yet? Register   Sign In
checkbox
#1

[eluser]black.Blank[/eluser]
is there any other way on how i can rewrite the following sample code?
Code:
if(in_array('sample1',$sample)
  $samp = 1;
  else if(!in_array('sample1',$sample)
  $samp = 0;

if(in_array('sample2',$sample)
  $samp2 = 1;
  else if(!in_array('sample2',$sample)
  $samp2 = 0;

if the checkbox is ticked, then the value for the corresponding field in the dbase will be 1 else 0.

thanks Smile
#2

[eluser]Cristian Gilè[/eluser]
Hi black.Blank,

try this:

Code:
$samples_num = 10;
    $samples = array('sample0','sample1','sample3');
    $amps = array();
    
    for($i=0;$i<$samples_num;$i++)
    {
        if(in_array('sample'.$i,$samples))
        {
          $amps[] = 1;
        }
        else
        {
          $amps[] = 0;
        }
    }
  
    print_r($amps);




Theme © iAndrew 2016 - Forum software by © MyBB