N字形变换

 $val) {
        array_push($data[$curRow], $val);
        if ($curRow == 0 || $curRow == $numRows - 1) $down = !$down;
        $down ? ++$curRow : --$curRow;
    }
    $result = [];
    array_map(function ($value) use (&$result) {
        $result = array_merge($result, array_values($value));
    }, $data);
    return implode('', $result);

}

$s = 'PAYPALISHIRING';
$r = convert($s, 3);
echo $r;#PAHNAPLSIIGYIR

你可能感兴趣的:(N字形变换)