如何简短这是PHP代码?

时间:2016-02-25 22:37:51

标签: php short

def fill(dir, x, y):
    base = matrix[y][x]
    if x < cols-1:
        best = base + cache[2, x + 1, y]
    else:
        best = base
    if dir != 0 and y > 0:
        best = max(best, base + cache[1, x, y - 1])
    if dir != 1 and y < rows - 1:
        best = max(best, base + cache[0, x, y + 1])
    cache[dir, x, y] = best


def maxsum(dir, x, y):
    for i in range(cols - 1, -1, -1):
        for j in range(rows - 1, -1, -1):
            fill(0, i, j)
        for j in range(rows):
            fill(1, i, j)
        for j in range(rows):
            fill(2, i, j)
    return cache[dir, x, y]

1 个答案:

答案 0 :(得分:2)

您可以使用in_array()函数来实现此目的。 PHP Manual in_array() funcion

将随机数保存在数组中并像这样检查

if (in_array($random, $numbers)) {
  //exist
}