Interview Questions and Answers

PHP interview questions & answers for freshers

Spread the love

PHP interview questions & answers for freshers –

Question 1. How many types of arrays supported by PHP?

Answer : There are 3 main types of arrays supported in PHP.

  • Indexed arrays: Indexed arrays contain numerical for for indexing elements.
  • Associative arrays: Associative arrays contain strings for indexing elements.
  • Multidimensional arrays: These are arrays that contain more than one index and dimension.

Question 2. What are the various constants predefined in PHP?

Answer : PHP consists of many constants, some of the more widely used as follows –

  • __FILE__: It denotes path and the file name
  • __METHOD__: Represents the class name
  • __FUNCTION__: Denotes the function name
  • __CLASS__: Returns the class name

Question 3. What is different between an indexed array & an associative array in PHP?

Answer : Indexed array is an array with a numeric key. The keys of an indexed array start at 0..
Associative arrays have strings as keys.

  • Example –
<?php
// Declaring an indexed array
$arr = array(9, 7, 30, 40, 56);
Output - 
Array : Array
(
    [0] => 9
    [1] => 7
    [2] => 30
    [3] => 40
    [4] => 56
)
// Declaring an associative array
$arr = array(
      "name" => "Ashok", 
      "age" => "30", 
      "mobileNo" => "1234567890"
);
Output -
Array : Array
(
    [name] => Ashok
    [age] => 30
    [mobileNo] => 1234567890
) 
?>

Question 4. What are sessions and cookies in PHP?

Answer : Sessions are global variables that are stored on the server side. In PHP, always initialize sessions using session_start().
PHP Cookies are also variables but it stored on the client’s web browser.A PHP cookie can be set using setcookie() function.

Question 5. How does define constant in PHP?

Answer : PHP Constants can be defined by making use of the define() function. It can not changes after defined.
They do not need to starting with $ sign.

PHP interview questions & answers for freshers

Leave a Reply

Your email address will not be published. Required fields are marked *