Loop code problem converting from Visual basic

Hi

I am converting a visual basic programme in excel into a webpage and am struggling with a php loop. My code creates a list of unique items:

VB code

N = 8
Options = 2 ^ (N - 2)
For i = 0 To Options - 1
j = 1

    statOutNo = vbNullString
    For k = 2 To N - 1
        If j And i Then
        statOutNo = statOutNo & ">" & k
 
        End If
        j = j + j
        
    Next k

'Debug.Print “1” & statOutNo & “>” & N
Next i

If N is 8 it creates a list as follows:

1>8
1>2>8
1>3>8
1>2>3>8
1>4>8

My PHP code is

$outcount = 8;
$ComplexJourneyComboOut = pow(2,($outcount-2));
for ($c=0; $c<$ComplexJourneyComboOut; $c++){
$j = 1;
$statOut = “”;
$StatNo = “”;
for ($d=2; $d<($outcount); $d++){

if ($j == $c) {
/$statOut = $statOut.($ItemsOut[($d-1)][‘StationAbb’]);/
$StatNo = $StatNo.’>’.$d;
}
$j = ($j+$j);

}

echo ‘1’.$StatNo.’>’.$outcount;
echo ‘

’;
}

But although the output of this starts off ok it doesn’t work. It produces:

1>8
1>2>8
1>3>8
1>8
1>4>8
1>8
1>8
1>8

I’m new to php and have wasted quite a few hours on this. I am hoping I have dones something simple wrong. Help greatly appreciated.

Try replacing…

if ($j == $c) {

With…

[quote]if(($j & $i) ==true) {

Sponsor our Newsletter | Privacy Policy | Terms of Service