六道php面试题附答案(共10篇)
六道php面试题附答案
1、不用新变量直接交换现有两个变量的值. (考php基本功)
答案:list($a, $b) = array($b, $a);
2、PHP数字金额转大小格式,同时说明思路 (考数组掌握)
3、SQL查询语句如下:
select * from table where (ID = 10) or (ID = 32) or (ID = 22) or (ID = 76) or (ID = 13) or (ID = 44)
让结果按10,32,22,76,13,44的'顺序检索出来,请问如何书写? (sql能力)
4、简单写一个上传文件程序,要求同时上传文件数量可以人为控制 (逻辑能力)
5、php同时调用3个数据库中的一个表的信息(架设A.a.aid=B.b.bid=C.c.cid),请说明思路及书写部分代码
6、现有一IM软件,使用id、email做为注册条件,假设已注册1040人,有一zh_cn论坛,使用id、email做为注册条件,假设已注册200人,有一en_us论坛,使用id、email做为注册条件,假设已注册150人
要求:将三者同步,使用统一的注册流程 ,写出设计思路
篇2:PHP面试题附答案
PHP面试题附答案
1. Which of the following will not add john to the users array?
1. $users[] = ‘john’;
2. array_add($users,’john’);
3. array_push($users,’john’);
4. $users ||= ‘john’;
Answer: 2,4
2. What’s the difference between sort, asort() and ksort(),rsort()? Under what circumstances would you use each of these?
sort(): 本函数对数组的值进行排序,当本函数结束时数组单元将被从最低到最高重新安排,array 中的单元赋予新的键名。这将删除原有的键名而不仅是重新排序。
asort(): 这个函数将数组的值重新排序,由小至大排列。数组的索引亦跟着值的 顺序而变动。当您在程序中需要重新整理数组值的 顺序时,就可以使用这个函数。
ksort(): 对数组按照键名排序,保留键名到数据的关联。本函数主要用于关联数组。
rsort(): 本函数对数组进行逆向排序(最高到最低)。与sort()执行相反的操作。
3. What would the following code print to the browser? Why?
$num = 10;
function multiply(){
$num = $num * 10;
}
multiply();
echo $num;
10
4. What is the difference between a reference and a regular variable? How do you pass by reference & why would you want to?
pass by reference like this functions(&$vars);
it likes more fast;
5. What functions can you use to add library code to the currently running script?
inlcude() or require();
6. What is the difference between foo() & @foo()?
if foo() throw a error, will be alert, but @foo() no;
7. How do you debug a PHP application?
xdebug or use die() do it;
8. What does === do? What’s an example of something that will give true for ‘==’, but not ‘===’?
=== 用于精确比较 ex: (” == null) =>true but ( ”===null) =>false;
9. How would you declare a class named “myclass” with no methods or properties?
class myclass{
}
10. How would you create an object, which is an instance of “myclass”?
$myoject = new myclass();
11. How do you access and set properties of a class from within the class?
getVar() or setVar() ;
12. What is the difference between include & include_once? include & require?
require:PHP 程式在执行前,就会先读入 require 所指定引入的档案,使它变成 PHP 程式网页的.一部份,
常用的函式,亦可以这个方法将它引入网页中。错误产生致命错误。
include:这个函式一般是放在流程控制的处理区段中。PHP 程式网页在读到 include 的档案时,才将它读进来。这种方式,可以把程式执行时的流程简单化。错误产生警报。
include_once:此行为和include()语句类似,唯一区别是如果该文件中的代码已经被包含了,则不会再次包含。如同此语句名字暗示的那样,只会包含一次。
13. What function would you use to redirect the browser to a new page?
1. redir()
篇3:php常用面试题及答案
1、谈对mvc的认识?
答:由模型(Model),视图(View),控制器(Controller)完成的应用程序
由模型发出要实现的功能到控制器,控制器接收组织功能传递给视图;
2、写出发贴数最多的十个人名字的SQL,利用下表:members(id,username,posts,pass,email)
答:SELECT * FROM `members` ORDER BY posts DESC limit 0,10;
3、GD库是做什么用的?
答:gd库提供了一系列用来处理图片的功能,使用GD库可以处理图片,或者生成图片。
在网站上GD库通常用来生成缩略图或者用来对图片加水印或者对网站数据生成报表。
4、请写出数据类型(int char varchar datetime text)的意思; 请问varchar和char有什么别?
答:int是数字类型,char固定长度字符串,varchar实际长度字符串,datetime日期时间型,text文本字符串
char的场地固定为创建表设置的长度,varchar为可变长度的字符
5、以下程序的输出结果?
$b=201;
$c=40;
$a=$b>$c?4:5;
echo $a;
?>
答:4
6、检测一个变量是否有设置的函数是?是否为空的函数是?
答:isset($str),empty($str);
7、得查询结果集总数的函数是?
答:mysql_num_rows($result);
8、$arr = array(‘james’, ‘tom’, ‘symfony’); 请打印出4:关于精选php面试题及答案
精选php面试题及答案
一、基础题
1. 写出如下程序的输出结果
<?php $str1 = null;
$str2 = false;
echo $str1==$str2 ? 相等 : 不相等;
$str3 = ;
$str4 = 0;
echo $str3==$str4 ? 相等 : 不相等;
$str5 = 0;
$str6 = 0;
echo $str5===$str6 ? 相等 : 不相等;?>
2. 写出如下程序的输出结果
<?php $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. 写出如下程序的输出结果
<?php $test = aaaaaa;
$abc = & $test;
unset($test);
echo $abc;?>
4. 写出如下程序的输出结果
<?php $count = 5;
function get_count(){
static $count = 0;
return $count ;
}
echo $count;
$count;
echo get_count();
echo get_count();?>
5. 写出如下程序的输出结果
<?php $GLOBALS[var1] = 5;
$var2 = 1;
function get_value(){
global $var2;
$var1 = 0;
return $var2 ;
}
get_value();
echo $var1;
echo $var2;?>
6. 写出如下程序的输出结果
<?php 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.常用php面试题及答案
2.php常用面试题及答案
3.PHP面试题汇总
4.优秀php高级工程师面试题及答案
5.百度PHP面试题
6.百度php面试题目
7.腾讯php面试题
8.提问得最多的PHP面试题
9.基础php面试题
10.百度php面试题
篇5:常用php面试题及答案
1.简述两种屏蔽php程序的notice警告的方法
初始化变量,文件开始设置错误级别或者修改php.ini 设置error_reporting
set_error_handler 和 @抑制错误
1.在程序中添加:error_reporting (E_ALL & ~E_NOTICE);
2.或者修改php.ini中的:error_reporting = E_ALL
改为:error_reporting = E_ALL & ~E_NOTICE
3.error_reporting(0);或者修改php.inidisplay_errors=Off
2.instanceof的作用, 经常在什么设计模式中使用
单例模式,但是其他的模式也会用到
3.1023用二进制表示, 并简述计算过程
10-2
1023%2=
511%2 =
255%2 =
127%2 =
63%2 =
31%2 =
15%2 =
7%2 =
3%2 =
1%2 =
0 =0
-------------------------------------------
1023
2^9=
51
k=9
10 9 8 7 6 5 4 3 2
1 1 1 1 1 1 1 1 1
----------------------
1023
1023-1/2=511
511-1/2=255
255-1/2=127
127-1/2=63
63-1/2=31
31-1/2=15
15-1/2=7
7-1/2=3
3-1/2=1
-----------------------------------------------
2-10
只需用将二进制数的各个位上的数从最右边开始,最右边的6:PHP面试题及答案
1.以下哪一句不会把 John 新增到 users 阵列?
$users[] = 'john';
成功把 John 新增到阵列 users。
array_add($users,’john’);
函式 array_add 无定义。
array_push($users,‘john’);
成功把 John 新增到阵列 users。
$users ||= 'john';
语法错误。
2.sort()、assort()、和 ksort() 有什么分别?它们分别在什么情况下使用?
sort()
根据阵列中元素的值,以英文字母顺序排序,索引键会由 0 到 n-1 重新编号。主要是当阵列索引键的值无关疼痒时用来把阵列排序。
assort()
PHP 没有 assort() 函式,所以可能是 asort() 的笔误。
asort()
与 sort() 一样把阵列的元素按英文字母顺序来排列,不同的是所有索引键都获得保留,特别适合替联想阵列排序。
ksort()
根据阵列中索引键的值,以英文字母顺序排序,特别适合用于希望把索引键排序的联想阵列。
3.以下的代码会产生什么?为什么?
$num =10;
function multiply(){
$num =$num *10;
}
multiply();
echo $num;
由于函式 multiply() 没有指定 $num 为全域变量(例如 global $num 或者 $_GLOBALS['num']),所以 $num 的值是 10。
4. reference 跟一个正规的变量有什么分别?如何 pass by reference?在什么情况下我们需要这样做?
Reference 传送的是变量的地址而非它的值,所以在函式中改变一个变量的值时,整个应用都见到这个变量的新值。
一个正规变量传送给函式的是它的值,当函式改变这个变量的值时,只有这个函式才见到新值,应用的其他部分仍然见到旧值。
$myVariable = ”its' value“;Myfunction(&$myVariable); // 以 reference 传送参数以 reference 传送参数给函式,可以使函式改变了的变量,即使在函式结束后仍然保留新值。
5.些函式可以用来在现正执行的脚本中插入函式库?
对这道题目不同的理解会有不同的答案,我的7:PHP面试题与答案
1. 禁用COOKIE 后 SEESION 还能用吗?
2. 抓取远程图片到本地,你会用什么函数?
4. 你觉得在pV10W的时候, 同等配置下,LUNIX 比WIN快多少?
5. 简述pOST 和GET传输的最大容量分别是多少?
6. 用最少的代码写一个求3值最大值的函数.
以下是部分答案(不保证是正确的解)
1. 不能
2 fsockopen
4 (不做优化的情况下一样)
5 2MB,1024B
6 function($a,$b,$c){
return $a>$b? ($a>$c? $a : $c) : ($b>$c? $b : $c );
}
―――――――――――――――――――――――――――C
大公司的pHp面试题
2. 求两个日期的差数,例如-2-5 ~ 2023-3-6 的日期差数
$begin=strtotime(‘2023-2-5′);
$end=strtotime(‘2023-3-6′);
echo ($end-$begin)/(24*3600);
3. 请写一个函数,实现以下功能:
字符串“open_door” 转换成 “OpenDoor”、”make_by_id” 转换成 ”MakeById”。
function str_change($str) {
$str = str_replace ( “_”, ” “, $str );
$str = ucwords ( $str );
$str = str_replace ( ” “, “”, $str );
return $str; }
4. 要求写一段程序,实现以下数组$arr1转换成数组$arr2:
$arr1 = array (
‘0′ =>array (‘fid’ =>1, ‘tid’ =>1, ‘name’ =>’Name1′ ),
‘1′ =>array (‘fid’ =>1, ‘tid’ =>2 , ‘name’ =>’Name2′ ),
‘2′ =>array (‘fid’ =>1, ‘tid’ =>5 , ‘name’ =>’Name3′ ),
‘3′ =>array (‘fid’ =>1, ‘tid’ =>7 , ‘name’ =>’Name4′ ),
‘4′ =>array (‘fid’ =>3, ‘tid’ =>9, ‘name’ =>’Name5′ )
);
$arr2 = array (
‘0′ =>array (
‘0′ =>array ( ‘tid’ =>1, ‘name’ =>‘Name1′),
‘1′ =>array ( ‘tid’ =>2, ‘name’ =>‘Name2′),
‘2′ =>array ( ‘tid’ =>5, ‘name’ =>‘Name3′),
‘
篇8:php工程师面试题及答案
php工程师面试题及答案