数组的回型输出
<?php /** * Created by PhpStorm. * Date: 2017/4/11 * Time: 14:02 */ class test1{ public function outArray($str){ $length = sizeof($str[0]); $height=sizeof($str); $total = $length * $height; $flag = 1; while($total){ //上 for($i = $flag -1;$i <= $length -$flag;$i++ ) { print($str[$flag - 1][$i]); $total--; if ($total == 0) { return 0; } } //右 for($j = $flag;$j<=$height-$flag-1;$j++){ print($str[$j][$length-$flag]); $total--; if($total==0){ return 0; } } //下 for($m = $length -$flag;$m>$flag-1;$m--) { print($str[$height - $flag][$m]); $total--; if ($total == 0) { return 0 ; } } //左 for($n = $height-$flag;$n>=$flag;$n--){ print($str[$n][$flag-1]); $total--; if($total==0){ return 0; } } $flag++; } } } $a = array( array(1,2,3,4), array(12,13,14,5), array(11,16,15,6), array(10,9,8,7) ); $c = array( array(1,2,3), array(8,9,4), array(7,6,5) ); $b = new test1(); $b->outArray($a);