Skip to content
Advertisement

For loop conversion problem from python to PHP

I try to convert the following Python function:

JavaScript

into a PHP function:

JavaScript

And when I test it:

JavaScript

I get the error:

JavaScript

for the line

JavaScript

And I don’t know how to solve it, do you have any ideas?

Advertisement

Answer

Python’s range(n) returns an array from 0 to n-1 while PHP’s range($n, $m) returns an array from $n to $m, so you have to use range(0, $l -1) there.

Also K.append(p+[j]) should be converted to $K[] = $p+[$j]; since $j is not an array.

The following function should work:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement