PHP程序员站--PHP编程开发平台
 当前位置:主页 >> PHP基础 >> 基础文章 >> 

PHP笔试题二

PHP笔试题二

来源:互联网  作者:本站整理  发布时间:2008-01-04
一、基础题 1. 写出如下程序的输出结果 ? $str1 = nu

一、基础题
1. 写出如下程序的输出结果
<?
$str1 = null;
$str2 = false;
echo $str1==$str2 ? '相等' : '不相等';
$str3 = '';
$str4 = 0;
echo $str3==$str4 ? '相等' : '不相等';
$str5 = 0;
$str6 = '0';
echo $str5===$str6 ? '相等' : '不相等';
?>

2. 写出如下程序的输出结果

以下为引用的内容:
<?
$a1 = null;
$a2 = false;
$a3 = 0;
$a4 = '';
$a5 = '0';
$a6 = 'null';
$a7 = array();
$a8 = array(array());
echo empty($a1) ? 'true' : 'false';
echo empty($a2) ? 'true' : 'false';
echo empty($a3) ? 'true' : 'false';
echo empty($a4) ? 'true' : 'false';
echo empty($a5) ? 'true' : 'false';
echo empty($a6) ? 'true' : 'false';
echo empty($a7) ? 'true' : 'false';
echo empty($a8) ? 'true' : 'false';
?>


3. 写出如下程序的输出结果
以下为引用的内容:
<?
$test = 'aaaaaa';
$abc = & $test;
unset($test);
echo $abc;
?>


4. 写出如下程序的输出结果
以下为引用的内容:

<?$count = 5;
function get_count(){
 static $count = 0;
 return $count++;
}
echo $count;
++$count;
echo get_count();
echo get_count();
?>


5. 写出如下程序的输出结果
以下为引用的内容:
<?
$GLOBALS['var1'] = 5;
$var2 = 1;
function get_value(){
 global $var2;
 $var1 = 0;
 return $var2++;
}
get_value();
echo $var1;
echo $var2;
?>


6. 写出如下程序的输出结果
以下为引用的内容:
<?
function get_arr($arr){
 unset($arr[0]);
}
$arr1 = array(1, 2);
$arr2 = array(1, 2);
get_arr(&$arr1);
get_arr($arr2);
echo count($arr1);
echo count($arr2);
?>

7. 使用五种以上方式获取一个文件的扩展名
要求:dir/upload.image.jpg,找出 .jpg 或者 jpg ,
必须使用PHP自带的处理函数进行处理,方法不能明显重复,可以封装成函数,比如 get_ext1($file_name), get_ext2($file_name)
 
二、算法题

1. 使用PHP描述冒泡排序和快速排序算法,对象可以是一个数组

2. 使用PHP描述顺序查找和二分查找(也叫做折半查找)算法,顺序查找必须考虑效率,对象可以是一个有序数组
3. 写一个二维数组排序算法函数,能够具有通用性,可以调用php内置函数
 

【附答案】(以下答案不一定是最好的,只是一个简单的参考)
一、基础题
1. 相等相等不相等
2. true true true true true false true false
3. aaaaaa
4. 5 0 1
5. 5 2
6. 1 2
7. 使用五种以上方式获取一个文件的扩展名

以下为引用的内容:
function get_ext1($file_name){
 return strrchr($file_name, '.');
}
function get_ext2($file_name){
 return substr($file_name, strrpos($file_name, '.'));
}
function get_ext3($file_name){
 return array_pop(explode('.', $file_name));
}
function get_ext4($file_name){
 $p = pathinfo($file_name);
 return $p['extension'];
}
function get_ext5($file_name){
 return strrev(substr(strrev($file_name), 0, strpos(strrev($file_name), '.')));
}
Tags: php   笔试题   php笔试题  
最新文章
推荐阅读
月点击排行榜
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号