接上文:PHP面试编程题汇总(3)
41. 以下程序运行结果正确的是
$str = "LAMP";
$str1 = "LAMPBrother";
$strc = strcmp($str, $str1);
switch ($strc) {
case 1:
echo "str > str1";
break;
case '–1':
echo "str < str1";
break;
case 0:
echo "str = str1";
break;
default:
echo "str <> str1";
}
输出的结果是:str <> str1
strcmp(str1,str2) 比较两个字符串的大小。会出现三种情况
- $str1==$str2 返回 0
- $str1 > $str2 返回 整数
- $str1 < $str2 返回负数
题中$strc的值为-7.(因为有7个字符不相等)
- 以下程序输出的结果正确是
$father = "mother";
$mother = "son";
echo $$father;
输出结果:son
$$表示引用
- 下列代码输出的是
$x = array("aaa", "ttt", "www", "ttt", "yyy", "tttt");
$y = array_count_values($x);
echo $y["ttt"];
输出结果:2
print_r($y);
Array ( [aaa] => 1 [ttt] => 2 [www] => 1 [yyy] => 1 [tttt] => 1 )
- date()会输出什么
$date="2009-5-19";
$time="14:31:38";
$datetime=$date.$time;
echo date("Y-m-d:H:i:s",strtotime($datetime));
输出结果:2009-05-19:14:31:38
echo date(“y-m-d:H:i:s”,strtotime($datetime)); 09-05-19:14:31:38
- 下面程序运行结果是
$array = [111,222,333];
foreach ($array as &$value){
var_dump($value);
}
foreach ($array as $value){
var_dump($value);
}
输出结果:
int(111) int(222) int(333)
int(111) int(222) int(222)
因为有 &号