I have to translate two Python functions into PHP. The first one is:
def listspaces(string):
return [i -1 for i in range(len(string)) if string.startswith(' ', i-1)]
I am assuming that this will check for space in provided string and return True when first occurrence of space is found, is this correct ?
What is i-1
here ? is it -1
?
In PHP we use []
for arrays . Here we are []
with return, will this function return true or false or array of locations of spaces ?
Second function is
def trimcopy(copy, spaces, length=350):
try:
if len(copy) < length:
return copy
else:
loc = 0
for space in spaces:
if space < length:
loc = space
else:
return copy[:loc]
except :
return None
Whats for space in spaces: here and whats is this return copy[:loc]