Hi everyone with this post we’re going to wind-up Elroi PHP Fresher Interview Questions with Answers.[Also see Elroi PHP Fresher Interview Questions with Answers – PART 1,Elroi PHP Fresher Interview Questions with Answers – PART 2,Elroi PHP Fresher Interview Questions with Answers – PART 3, Elroi PHP Fresher Interview Questions with Answers–PART 4Let us discuss the remaining questions in this post;

Elroi PHP Fresher Interview Questions with Answers–PART 5

26.What is count? When do you use it?

The count() function is used to count the elements of an array or the properties of an object.

count(array_name, mode)

            Name        Description       Required /
array_name Specifies the array or object to count. Required Array
mode Sets the mode of the function.
Possible values :
COUNT_RECURSIVE (or 1) : here the count() function counts the array recursively. This is useful for counting all the elements of a multidimensional array. 
The default value is 0.
Optional Integer

The number of elements in array_name.

27.What is the function to find length of the string?

The strlen() function returns the length of a string.
string-Specifies the string to check
Returns the length of a string on success, and 0 if the string is empty.

28.Write program for while loop?

$i = 0;
while ($i < 5){
echo $i + 1 . “<br>”;

29.What is inheritance?write program for inheritance?types-of-inheritance

=>When a class is defined by inheriting existing function of a parent class then it is called inheritance.
=>The child class will inherit all or few member functions and variables of a parent class.
=>PHP class definitions can optionally inherit from a parent class definition by using the extends clause.
class Child extends Parent {
<definition body>
//The parent class
class Car {
// Private property inside the class
private $model;

//Public setter method
public function setModel($model)
$this -> model = $model;

public function hello()
return “Hello! I am a <i>” . $this -> model . “</i><br />”;

//The child class inherits the code from the parent class
class SportsCar extends Car {
//No code in the child class

//Create an instance from the child class
$sportsCar1 = new SportsCar();

// Set the value of the class’ property.
// For this aim, we use a method that we created in the parent
$sportsCar1 -> setModel(‘Mercedes Benz’);

//Use another method that the child class inherited from the parent class
echo $sportsCar1 -> hello();

Hello!I am a Mercedes Benz

30.What is the new version of phpuse now?when it was launched?

=>The latest version of php is PHP 7.2.
=>It was launched on 30th November 2017.
=>It is supported until 30th November 2020.
=>Based on performance benchmarks run by Phoronix, PHP 7.2 runs up to 13% faster than PHP 7.1, or 20% faster than PHP 7.0. And compared to PHP 5.6, PHP 7.2 is over 250% faster.

31.What is encryption and decryption?EN AND DE


Encrypts given data with given method and key, returns a raw or base64 encoded string
string openssl_encrypt ( string $data , string $method , string $key [, int $options = 0 [, string $iv = “” [, string &$tag = NULL [, string $aad = “” [, int $tag_length = 16 ]]]]] )
=>data-The plaintext message data to be encrypted.
=>method-The cipher method. For a list of available cipher methods, use openssl_get_cipher_methods().
=>key-The key.
=>options-options is a bitwise disjunction of the flags OPENSSL_RAW_DATA and OPENSSL_ZERO_PADDING.
=>iv-A non-NULL Initialization Vector.
=>tag-The authentication tag passed by reference when using AEAD cipher mode (GCM or CCM).
=>aad-Additional authentication data.
=>tag_length-The length of the authentication tag. Its value can be between 4 and 16 for GCM mode.
Returns the encrypted string on success or FALSE on failure.


Decrypts the data and returns the unencrypted data.
string mcrypt_decrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] )
=>cipher-One of the MCRYPT_ciphername constants, or the name of the algorithm as string.
=>key-The key with which the data was encrypted. If the provided key size is not supported by the cipher, the function will emit a warning and return FALSE
=>data-The data that will be decrypted with the given cipher and mode. If the size of the data is not n * blocksize, the data will be padded with ‘\0’.
=>mode-One of the MCRYPT_MODE_modename constants, or one of the following strings: “ecb”, “cbc”, “cfb”, “ofb”, “nofb” or “stream”.
=>iv-Used for the initialization in CBC, CFB, OFB modes, and in some algorithms in STREAM mode. If the provided IV size is not supported by the chaining mode or no IV was provided, but the chaining mode requires one, the function will emit a warning and return FALSE.
Returns the decrypted data as a string or FALSE on failure.

32.What function to upload image in php?

=>In your “php.ini” file, search for the file_uploads directive, and set it to On:
file_uploads = On
=>If the value assigned to the input’s name attribute in uploading form was file, then PHP would create following five variables −
$_FILES[‘file’][‘tmp_name’] − the uploaded file in the temporary directory on the web server.
$_FILES[‘file’][‘name’] − the actual name of the uploaded file.
$_FILES[‘file’][‘size’] − the size in bytes of the uploaded file.
$_FILES[‘file’][‘type’] − the MIME type of the uploaded file.
$_FILES[‘file’][‘error’] − the error code associated with this file upload.
$target_dir = “uploads/”;
$target_file = $target_dir . basename($_FILES[“fileToUpload”][“name”]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST[“submit”])) {
$check = getimagesize($_FILES[“fileToUpload”][“tmp_name”]);
if($check !== false) {
echo “File is an image – ” . $check[“mime”] . “.”;
$uploadOk = 1;
} else {
echo “File is not an image.”;
$uploadOk = 0;
// Check if file already exists
if (file_exists($target_file)) {
echo “Sorry, file already exists.”;
$uploadOk = 0;
// Check file size
if ($_FILES[“fileToUpload”][“size”] > 500000) {
echo “Sorry, your file is too large.”;
$uploadOk = 0;
// Allow certain file formats
if($imageFileType != “jpg” && $imageFileType != “png” && $imageFileType != “jpeg”
&& $imageFileType != “gif” ) {
echo “Sorry, only JPG, JPEG, PNG & GIF files are allowed.”;
$uploadOk = 0;
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo “Sorry, your file was not uploaded.”;
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES[“fileToUpload”][“tmp_name”], $target_file)) {
echo “The file “. basename( $_FILES[“fileToUpload”][“name”]). ” has been uploaded.”;
} else {
echo “Sorry, there was an error uploading your file.”;