PHP Interview Questions(18)

面试时间:2020-02-20,星期四,上午 10:30。

1. 怎么获取字符串倒数第二个字符。

function getSecondLastChar($string) {
    $length = strlen($string);

    if ($length >= 2) {
        return $string[$length - 2];
    } else {
        return '';
function getSecondLastChar($string) {
    return $string[-2];

2.常用的框架 区别

 763 total views

PHP Interview Questions(17)


1.What does “&” mean in ‘&$var’?

Passing by Reference

2.What is MVC?

MVC is a design pattern used to decouple user-interface (view), data (model), and application logic (controller). This pattern helps to achieve separation of concerns.

3.What is the difference between $_GET and $_POST?

$_GET — HTTP GET variables
$_POST — HTTP POST variables

4.What will be the output of each statements below and why?

var_dump(0123 == 123);

var_dump(‘0123’ == 123);

var_dump(‘0123’ === 123);


5.After the code below is exexuted, what will be the value of $text and what will be strlen($text) return? Explain your answer.

$text = ‘John ‘;

$text[10] = ‘Doe’;

$text = 'John      D';
strlen($text) = 11;


1.What is the potential pitfall with using typeof bar == “object” to determine if bar is an object? How can this pitfall be avoided?

typeof null == "object"
bar != null && typeof bar == "object"

2.What is NaN? What is its type? How can you reliably test if a value is equal to NaN?

Not a number

3.What is the difference between jQuery.get() and jQuery.ajax()?

$.get(url, data, success, dataType) is a shorthand Ajax function, which is equivalent to:

  url: url,
  data: data,
  success: success,
  dataType: dataType

4.Write a simple function(less than 80 characters) returns a boolean indicating whether or not a string is palindrome.

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers.

console.log(isPalindrome("level"));                    // logs 'true'
console.log(isPalindrome("levels"));                   // logs 'false'
console.log(isPalindrome("A car, a man, a maraca"));   // logs 'true'

function isPalindrome(str) {
    str = str.replace(/\W/g, "").toLowerCase();
    return str.split("").reverse().join("") == str;

 5,583 total views