前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >基础面试题php

基础面试题php

作者头像
友儿
发布2022-09-11 12:41:19
1840
发布2022-09-11 12:41:19
举报
文章被收录于专栏:友儿友儿
代码语言:javascript
复制
2.What is the value of $x after the following code?
$x = 1;
$y = 2;
if ($x != $y)
$x = $x * $y;
else
$x = $x + $y;
a. 2
b. NULL
c. 3
d. 1

3.Which of the following is the correct use of the concatenation operator?
a. $x = $This & $That;
b. $x = $This && $That;
c. $x = $This + $That;
d. $x = $This . $That;
4.What is the value of $x after the following code?
$foo = 1;
$foo += 5;
$x = $Foo;
a. NULL
b. 1
c. 5
d. 6
5.Which of the following is NOT a valid way to increment $nothing?
a. ++$nothing;
b. $nothing = $n + $nothing;
c. $nothing = +$n;
d. $nothing++;
6.Which of the following is a valid variable name?
a. $1Var
b. 1Var
c. $My-Var
d. $MyVar
7.Which of the following answers is a valid database connection statement, based on the following  code?
$hostname = 'localhost';
$user = 'root';
$password = 'sesame';
$database 'Employees';*
a. mysql_connect($database, $database, $user, $password);
b. mysql_connect($hostname, $user, $password, $database);
c. mysql_connect($hostname, $user, $password);
d. mysql_connect($hostname, $database);
8.Which of the following is a valid SELECT statement?*
a. $SQL = 'SELECT name, address FROM customers WHERE id = 1';
b. $SQL = 'FROM customers SELECT name, address WHERE id = 1';
c. $SQL = 'SELECT name, address, id = 1 FROM customers';
d. $SQL = 'SELECT name, address WHERE id = 1 FROM customers';
9.What is the output of the following expression: 
$a = "b";
$b = "c";
$c = "a";
echo $$$$a;
a. Parse
b. c
c. a
d. b
10.What is the output of the following expression
$d = 10;
function myFunction($d) {  
  return ++$d;
}
myFunction($d++);
echo $d;*
a. NULL
b. 12
c. 10
d. 11
11.What is the output of the following expression: 
$f = 7;
function myFunction(&$d) {
  return $d++;
}myFunction($f);
echo $f;*
a. None of the above
b. 7
c. 78
d. 8
12.What is the output of the following expression: 
$a = array(1, 2, 3, 4, 5);
echo array_shift($a);*
a. 5
b. null
c. 1
d. 1,2,3,4,5
13.What is the output of the following code: 
class myClass {
  public $z;
  public function __construct($z = 5) {
    $this->z = 10;
  }
}

$a = new myClass();
$b = $a;
$b->z = 0;
echo $a->z;*
a. 5
b. 0
c. 15
d. 10
14.What is the value of the array $a:
$a = array_combine(array('A', 'B', 'C'), array(1, 2, 3));
a. array(1 => 'A', 2 => 'B', 3 => 'C')
b. array('A' => 1, 'B' => 2, 'C' => 3)
c. array(array('A', 'B', 'C'), array(1, 2, 3))
d. array('A', 'B', 'C', 1, 2, 3)
15.Which of the following expressions correctly checks the type AND value so that the expression evaluates to FALSE? 
$a = '';
$b = 0;*
a. $a == false
b. $b === false
c. !$a
d. $b == false
16.What does the following string do? 
$rest = substr ("abcdef", 1, 3);*
a. sets the variable $rest to "def"
b. sets the variable $rest to "cdf"
c. sets the variable $rest to "abc"
d. sets the variable $rest to "bcd"
17.What is the output of the following code: 
class A {
  protected $x = 10;

   public function myMethod($x=0) {
    return $this->x;
  }
} 

class B extends A {
  public function myMethod($x=0) {
    return 2 * $this->x;
  }
} 

$m = new B(5);
echo $m->myMethod();
a. 15
b. 5
c. 10
d. 20
18.What is the output of the following code:
$vehicles = array('car', 'truck', 'van', 'bus');
current($vehicles);
next($vehicles);
each($vehicles);
echo current($vehicles);*
a. car
b. truck
c. bus
d. van
19.What is the output of the following code: 
switch (5 % 2) {
  case 1:
    echo 1;
  case 2:
    echo 2;
  case 3:
    echo 3;
  break;
  default:
    echo 0;
}*
a. 12
b. 1
c. 0
d. 123
20.If you wanted to use the ASP escape characters(<% %>), what do you need to do?
a. Install PHP with ASP support checked
b. Edit the php.ini file and change USEASPCHARACTERS to TRUE.
c. Nothing, PHP uses them by default.
d. Edit the php.ini file and change asp_tags to On.

21.Which expression does not result in $a = 5?
a. $a = ($b = 5);
b. $a = 4; $a = $a++;
c. $a = 4; $a = ++$a;
d. $a = $b = 5;
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档