81.  

What are the different errors in PHP?

There are 4 basically types of error.
 

Example:
  • Parse Error – Commonly caused due to syntax mistakes in codes e.g. missing semicolon, mismatch brackets.
  • Fatal Error – These are basically run time errors which are caused when you try to access what can’t be done. E.g. accessing a dead object, or trying to use a function that hasn’t been declared.
  • Warning Error – These occurs when u try to include a file that is not present, or delete a file that is not on the server. This will not halt the script; it will give the notice and continue with the next line of the script.
  • Notice Error – These errors occurs when u try to use a variable that hasn’t been declared, this will not halt the script, It will give the notice and continue with the next line of the script.
82.  

What is an associative array?

Associative arrays are arrays that use named keys that you assign to them.

Example:

 


    

<?php   

$capitals=array("India"=>"New Delhi","China"=>"Beijing","Pakistan"=>"Islamabad");

?>

 

 

 

83.  

What is PDO classes?
 

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. It is a data-access abstraction layer, so no matter what database we use the function to issue queries and fetch data will be same. Using PDO drivers we can connect to database like DB2, Oracle, PostgreSQL etc.

84.  

What are the different types of PHP variables?

PHP has a total of eight data types which we use to construct our variables −

Example:
  • Integers − are whole numbers, without a decimal point, like 4195.
  • Doubles − are floating-point numbers, like 3.14159 or 49.1.
  • Booleans − have only two possible values either true or false.
  • NULL − is a special type that only has one value: NULL.
  • Strings − are sequences of characters, like 'PHP supports string operations.'
  • Arrays − are named and indexed collections of other values.
  • Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
  • Resources − are special variables that hold references to resources external to PHP (such as database connections).
     
85.  

What are the differences between PHP constants and variables?

  • There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.
  • Constants cannot be defined by simple assignment, they may only be defined using the define() function.
  • Constants may be defined and accessed anywhere without regard to variable scoping rules.
  • Once the Constants have been set, may not be redefined or undefined.
86.  

Explain the syntax for 'foreach' loop.

The foreach statement is used to loop through arrays. For each pass the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass next element will be processed.

Example:

foreach (array as value)

{

code to be executed;

}

 

 

 

87.  

How will you concatenate two strings in PHP?

To concatenate two string variables together, use the dot (.) operator −

Example:

<?php

$string1="Hello World";

$string2="1234";
echo $string1 . " " . $string2;
?>

 

This will produce following result −

Hello World 1234
 


 

 

88.  

How will you generate random numbers using PHP?

The PHP rand() function is used to generate a random number. This function can generate numbers with-in a given range. The random number generator should be seeded to prevent a regular pattern of numbers being generated. 

89.  

What is the purpse $_REQUEST variable?.

The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. We will discuss $_COOKIE variable when we will explain about cookies. The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.