六間房的兩個PHP面試題

來源:互聯網
上載者:User

 

<?php/*=============================================================================#     FileName: base64.php#         Desc: 六間房筆試題一:讀取一個檔案,將其Base64編碼,每76個字元加一個換行 #       Author: HouYongZheng#         Time: 2013-05-20 14:25=============================================================================*/header('Content-Type: text/html; charset=utf-8');$body=file_get_contents('base64.txt');$base_body=base64_encode($body);$count=1;for($i=0;$i<strlen($base_body);$i=$i+76){$index=($count-1)*76;@$all_str.='<p>'.substr($base_body,$index,76).'</p>';$count++;}echo $all_str;?>
<?php/*=============================================================================#     FileName: array.php#         Desc: 六間房筆試題二:寫一個函數,參數為$n,產生一個數組,其元素為1~$n,各元素位置隨機排列,不得重複#       Author: HouYongZheng#         Time: 2013-05-20 15:01=============================================================================*/function rand_array($n){$array=array();$rand_array=array();for($i=1;$i<=$n;$i++){array_push($array,$i);}//return $array;for($i=0;$i<=($n-1);$i++){$rand=array_rand($array,1);array_push($rand_array,$array[$rand]);unset($array[$rand]);}return $rand_array;}var_dump(rand_array(10));?>


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.