Skip to content

Instantly share code, notes, and snippets.

@alexzhou
Created June 21, 2014 14:57
Show Gist options
  • Save alexzhou/cee9d5352b468740f500 to your computer and use it in GitHub Desktop.
Save alexzhou/cee9d5352b468740f500 to your computer and use it in GitHub Desktop.
《编程珠玑》翻转字符串算法
<?php
function reverse($arr, $len, $m){
$k = 0;
for($i = 0; $i < $m; $i++){
$k = 1;
$temp = $arr[$i];
while(($k*$m+$i) % $len != $i){
$arr[($k-1)*$m+$i] = $arr[$k*$m+$i];
$k++;
}
$arr[($k-1)*$m+$i] = $temp;
}
return $arr;
}
@alexzhou
Copy link
Author

Has php Notice about array offset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment