views:

73

answers:

1

I do have a function which do calculations a lot.

$arrleft and $arrright are two different arrays. what I am doing here is I am combining two to produce together output for my current application. what I done is a simple method and it eats lots of space and time. what I want is if any one can make this code to a couple of lines shorter(I know it can be if it in loop). but cant get into by myself so I am putting it here for your opinion.

  $arrleft = explode(',' , $data1);
$arrright = explode(',' , $data2); if(isset($data1,$data2)){if(isset($arrleft[0],$arrright[0],$arrleft[1],$arrright[1],$arrleft[2],$arrright[2],$arrleft[3],$arrright[3],$arrleft[4],$arrright[4]))
     { $totalnumber = ($valueset+1)//calculate total number of variables set + 1 here $valueset = 4 so $total number (4+1)=5
       $value = (0, 0, $arrleft[0]);
       $value1 = (0, 1, $arrright[0]);
       $value2 = (1, 0, $arrleft[1]);
       $value3 = (1, 1, $arrright[1]);
       $value4 = (2, 0, $arrleft[2]);
       $value5 = (2, 1, $arrright[2]);
       $value6 = (3, 0, $arrleft[3]);
       $value7 = (3, 1, $arrright[3]);
       $value8 = (4, 0, $arrleft[4]);
       $value9 = (4, 1, $arrright[4]);
     }else if(isset($arrleft[0],$arrright[0],$arrleft[1],$arrright[1],$arrleft[2],$arrright[2],$arrleft[3],$arrright[3])){ 
       $totalnumber = ($valueset+1)//calculate total number of variables set + 1 here $valueset = 3 so $total number (3+1)=4
       $value = (0, 0, $arrleft[0]);
       $value1 = (0, 1, $arrright[0]);
       $value2 = (1, 0, $arrleft[1]);
       $value3 = (1, 1, $arrright[1]);
       $value4 = (2, 0, $arrleft[2]);
       $value5 = (2, 1, $arrright[2]);
       $value6 = (3, 0, $arrleft[3]);
       $value7 = (3, 1, $arrright[3]);
     }else if(isset($arrleft[0],$arrright[0],$arrleft[1],$arrright[1],$arrleft[2],$arrright[2])){
        $totalnumber = ($valueset+1)//calculate total number of variables set + 1 here $valueset = 2 so $total number (2+1)=3
       $value = (0, 0, $arrleft[0]);
       $value1 = (0, 1, $arrright[0]);
       $value2 = (1, 0, $arrleft[1]);
       $value3 = (1, 1, $arrright[1]);
       $value4 = (2, 0, $arrleft[2]);
       $value5 = (2, 1, $arrright[2]);
     }else{}
}

I have reduced lots of lines here due to space issue.

A: 
System