Category Archives: PHP

Articles and Interview Questions,Tips related to PHP – Interview Sortout

Drupal Interview Questions and Answers

Drupal is a Powerful CMS. Flexibility of Drupal makes it popular and Lovable Framework.  Since Drupal is a Popular CMS and Website Development tool based on PHP there is huge demand of Drupal Professionals. If you are also a Drupal Developer or want to Find a Job in Drupal Development Profile then You should prepare these Drupal Interview Questions. These are the important Drupal Interview Questions and specially designed for both freshers and as well as intermediate level of experience professionals.

We have listed here top Drupal Interview Questions and Answers:

What is Drupal?
Drupal is an open source Content Management System and used for Complex websites. It has great flexibility of functionality and modularity. We can design our website using the core of Drupal and we can manage content on pages easily. Nowadays Drupal is used for e-commerce stores, blogging, business sites, college and universities websites.

What are the main features of Drupal?
Main features of Drupal are listed as:
-Open Source
-Flexible and Robust CMS in comparison to Others.
-Provide Security layer.
-Easy to manage Content.
-Fields and Blocks that are the most flexible assets of Drupal.

How Drupal is different from other CMSs available as opensource?
Drupal has a complex structure, and a heavy core so it is not suitable for small websites. It is secure than any other CMS.It has a great functionality to manage content and visibility. It provides a robust user management module in core.

What is the .info file in a Drupal theme?
This is the configuration setting of the Drupal theme. A .info file is a static content and settings are written here as key=value format. Each line has a different key and value for that. Metadata, style sheets, JavaScripts, block regions and more can be defined here. It is used for theme and not for the module.

What is a theme?
The theme is a collection of files to construct the layout. A Drupal theme contains following important elements:
– Configuration file (.info)
– Templates file (.tpl.php)
– Stylesheets
– sub-themes

What is Module in Drupal?
A module in Drupal is a collection of PHP files to provide some additional functionality to Drupal site. A module can access all the core functions and variables of the Drupal.

What is Block?
Blocks are the layout elements. A block defines that what particular content should be displayed at what place in the layout. It is a box in the content area.

How can we add modules to the core?
We can upload compressed files of the module or we can directly import from the remote URL.

What are the regions?
Regions are the layers defined by theme to represent the content area. For example footer, sidebar, navigation etc.

What is a node?
All the contents are treated as a node in Drupal. A node is a chunk of content. We create content, custom content using node module.

What is taxonomy?
Taxonomy is used to organize Metadata, tags, categories in Drupal. It a feature of Drupal core. It is used to categorize the content of the website. We can use tags to connect the content.

What is sub-theme?
A sub-theme is child theme. It inherits the resources of the Parent theme. It can be chained. A sub-theme can be a child of another sub-theme. All the styles sheets and javascript inherited by sub-theme.

What is service.yml?
service.yml placed in the root directory in and all the services are defined here.

What are properties of services?
Services may have following properties:
-abstract
-alias
-tag
-arguments
-calls
-class
-factory
-file
-public
-scope

What is settings.php?
This is the global settings of the site.Tthe database, URL structure, salt, encryption etc all the variables are defined here.

What is clean URL?
SEO friendly URLs in Drupal is clean URL.We can enable or disable it.

How can we manage clean URL in Drupal?
We can enable or disable clean URLs by following steps:
-navigate to Administer > Configuration > Search and metadata > Clean URLs
-Wait for the automated Clean URLs test to run.
-Check or uncheck the Enable clean URLs checkbox
-Click “Save configuration”

What is URL alias?
We can add our custom URL in place of “node”. It makes URL clean and SEO friendly.

What does cron do in Drupal?
Cron deletes temporary files and trigger the search module to index the content on the site.It pings modules to get updates.

What is Report in Drupal?
Reports modules collect the site health report and logs.It does the following task:
-Recent log entries
-Top ‘access denied’ errors
-Top ‘page not found’ error
-Available updates
-Status Report
-Site statistics

What is the status report?
Here you can find a short overview of your site’s parameters as well as any problems detected with your installation.

What is Recent Log entries?
The Database Logging module logs system events in the Drupal database. Monitor your site or debug site problems on this page.

What are the content types in Drupal?
Contents are categorized into 2 basic categories:
1- Basic pages
2- Articles

What is Basic page content?
Basic Page is the landing pages for a site, that rarely change. If we are creating About us, Contact us, Services, Team pages then we have to choose Basic Page type content.

What is Article type content?
Article type is a regular blog post on the site. We can select Article if we are writing an article or blog posts related to latest updates, hobbies etc.

Spread the love

15 Advance Code Igniter Interview Questions and Answer


How routing is beneficial in Code Igniter?
Routing provides a way to alter your URL and redefine it according to you. It helps in security and SEO. We can create URL having keywords and phrases influential for SEO ranking.What is a helper?
Helpers are the file having functions for specific purposes. We can directly call them in our script.There is numerous type of helper:
  • Array Helper: It has functions that we use to manipulate arrays.
  • File Helper: Use of this helper is to play with files as upload an image.
  • HTML Helper : Html helper is used to compose HTML dom using php code.
  • URL Helper: We use it to create and construct or redirect URLs.
What does autoload.php do?

It loads when the application start loading contains and default parts of application call. It has information to load the segments that we need to load automatically. For example, we may need to load some models automatically.

How can we connect code igniter to our database?
There is a database.php file in the config directory. We can put here our database information like database name, hostname, username and password and It will be connected.

Can we call multiple model function in a single controller function?
Yes, of course. We can call any number of model and their functions in a single controller class?

Can we write database queries in a controller?
Yes, we can write database queries directly in controllers but this is not a good practice. We should write database queries always in the model.

How can we pass data to view?
We create an array having a particular key and pass this array to load view call. We will have this data on the view page as having the name of the key given to data array.

<?php
$data['employee']=array("name"=>"Dhananjay");
$this->load->view("employee_info",$data);
?>

Now on the employee_info.php page, we will have a $employee variable and that will store the data passed in the array $data in the controller.

How can we pass a parameter to controller function?
A parameter can be passed to URL segment after backslash next to function route. Suppose “admin” is a controller , “all_user” is a function and “active” is a parameter. Now we have to pass this to function that it can list the active user so we can call as given below:

<?php echo site_url("admin/all_user/active")?>

What is a library in Code Igniter?
Code Igniter library is a utility to extend the functionality and to use some predefined functions and classes. We have different libraries for different purposes as upload, database etc.

How can we execute a raw query in Code Igniter?
Using query builder library of code igniter we can execute raw query. For example,

db->query($sql);
$result=$query->result_array();
?>

What is URL helper?
We use URL helper to do manipulation with URL. We can easily create custom URL, we can extract parameters from URL, we can easily create custom anchors, form action, and page redirection.

How the database library provide strength to Code Igniter framework?
Database library has query builder functions. It works with single data and also in batch data. It accepts the array and single values as parameters. Functions are very similar to MySQL query phrases and keywords. We can use almost the query using query builder. It fetches the data in all possible formats. We can select, update, join, delete the records in very simple and robust way.

How we will submit data using a form on code igniter view?
We can give the controller function route as the form action. When we will submit this for, the controller function will be called and data will be collected using $_GET or $_POST arrays, as the method defined in the form.

How we create a session variable and how will we get that value stored in a session variable?
Code igniter has session library.It uses four types of the driver to store session data:
1-files
2-database
3-redis
4-Memcached
The file is the default storage.
After loading session library we can use session class and its method to set or get the session value.

<?php 
$this->load->library('session');
//set session data
$this->session->set_userdata('user_session_name', 'session_value');

//check session
$this->session->has_userdata('user_session_name', 'session_value');

//get session data
$this->session->get_userdata('user_session_name', 'session_value');

//destroy session data
$this->session->unset_userdata('user_session_name');
?>

How can we upload any file in Code Igniter application?
Code igniter has upload library. We will use this library and set preferences in $config variable.
After initializing library we use call do_upload() function and it will complete the task.

Spread the love

Most Common PHP-MySQL Interview Questions and Answers

There are some basic PHP Interview questions, asked in every interview often. They must be known to every interview aspirants.

Chances of asking these questions by Interviewer is very high because they just test your basic concepts of PHP. They highlight your understanding and command of the language. They are helpful to nail the first impression on the interviewer when you are in the interview.

An Interviewer expects that you should know the answers to these questions. After these questions, you will be asked to answer some hard-core questions and concepts.

What we have given here is experienced. these questions give you the pattern of often asked questions on Interviews along with their answers.

We try to give genuine answers, by verifying them from www.php.net, www.w3schools.com, and other popular tutorials site. After knowing the pattern It will be easy for you to explore more questions from various sources.

What is PHP?
PHP is a server-side scripting language. It is lightweight as well as enriched with OOPs features. PHP is freely available and has lots of frameworks, CMS to built robust and secure applications.

Explain these functions :
echo( ),print( ),print_r( ),die( ),exit( ),var_dump( )
var_dump($var):- Displays information about a variable.
echo() or echo: This is not actually a function.This doesn’t return a value after it takes parameter.
print() pritn : This is also not a function ,accepts always single parameter and returns 1.
print_r():-This prints the content and indexes of arrays and objects.
exit:-It terminates the current script with a message.
die(): This is identical to exit;

What are the differences amongst include(), require(),require_once(), require(),include()?
include(): Includes an external script into current script. On failure it emits Warning and allows script to continue, it does not terminate the execution of the script.
include_once(): On failure emits an compile E_COMPILE_ERROR  error. It terminates the script execution.

What is the difference between in_array() and is_array()?
Both of these function returns a boolean type.
in_array() :
If a value finds within an array it returns TRUE otherwise returns false.
is_array() :
It checks whether the type of variable is an array or not. It returns true if an array is passed into it. It can be applied to any type of array.

What is the difference between count() and sizeof()?
Literally we can say there is no difference between these two terms. Both of these have Identical behaviors.
count():- It counts all elements of an array or object.
sizeof():-Identical to count(), can say Alias.

What is the difference between json_encode() and json_decode()?
json_encode() converts a PHP array or an object into json string, and json_decode() convers an JSON string into PHP array or into PHP object.

Where do we store Session and Cookie?
The session is stored on the server whereas cookies are stored on the client machine in browsers.

How we use foreach loop in PHP?
Foreach loop is used to iterate an array or an object in PHP. For example

<?php 
foreach ($array as $key =>; $value){
echo "$value is at $key place";
}
?>

What are the differences amongst trim(),ltrim(),rtrim()?

  • trim():-It removes white spaces from both the sides of a string.
  • ltrim():-It removes white space from the left side of a string.
  • rtrim():-It removes white space from the right side of a string.

What are the constants , how we define them in PHP?
A constant is a name assigned to a value. It is like Identifiers but cannot change during script execution. We can define them usually in UPPER_CASE underscored string without $. For example: define(“CURRENT_YEAR”, “2017”);


What is $_GLOBAL?
$_GLOBAL Is a superglobal array and holds all the variables that are global and can be accessed from anywhere in the script. $_POST,$_GET,$_REQUEST,$_FILE,$_SESSION,$_COOKIE all are superglobal arrays available in PHP. We can call them anywhere in the script.


What is the difference between MySQL and mysqli?
MySQLi is the extension of MySQL and It is an improved version of MySQL. MySQLi supports OOPS features and compatible with PDO.


What unlink() function do in PHP?
It is used to delete a file or directory from its location.

What are the basic differences amongst Warning, Fatal Error, and Notice?
Fatal error results in the termination of the script, no further execution of the script is possible when it happens. Whereas Notice does not terminate the script, rather it notifies about some tolerable mistake and script after that line is able to execute. Warnings are the deprecated and bearable things in scripts. This doesn’t affect the result usually.

Which function is used to send email in PHP?
The mail() function is used to send emails in PHP. Learn more about The PHP mail() Function.

What is the difference between array_diff() and array_filter()?
array_diff() returns the array of values of difference of two arrays and array_filter() returns the arrays of values and filter null values or specific values. The function array_filter() also used a callback function but it is optional.


What is the difference between array_serach() and in_array()?
The method array_search() returns the key if the value is found in the array and the function in_array() return TRUE if it will find the values in the array. In case of a failure, both functions return FALSE.


What strlen() do?
strlen() is a PHP library function and it returns the length of string passed to it.


How substr() works?
substr() is a PHP library function and it returns the part of string passed with parameters to it. It accepts starting point, length of returning string and input string as parameters.


How str_replace() works?
It is used to replace a sub-string with another substring in an input string.

 

Spread the love

Top 10 Interview Questions and Answers for PHP freshers

What is difference between $_GET and $_POST?
$_GET stores data sent by HTML form ‘get’ method or the value of variable encoded with URL whereas the $_POST collects the data submitted by “post” method of HTML form. $_GET has a character limit whereas no such limit defined by PHP for the POST.


How many types of array are there in PHP?
Basically, there are three types of arrays in PHP
1- Indexed arrays
2- Associative arrays
3- Multidimensional Arrays


How to convert a string into array and vice-versa?
We can cover an array into a string and a string into an array using explode() and implode() methods.These methods use some delimiter to concat values of arrays and also at the time of splitting a string into an array.

How you can find IP address of Local machine accessing PHP sites?
PHP has a number of superglobals.$_SERVER has some autodetected values. We can use this variable to get the IP address as given below:

1
$_SERVER[‘REMOTE_ADDR’] ; ?>



In how many ways we can fetch data from MySQL database?
There are four standard ways to fetch data from MySQL database in PHP. They are listed below:
1-mysql_fetch_array()
2-mysql_fetch_assoc()
3-mysql_fetch_row()
4-mysql_fetch_object()

Is PHP an Open Source?
Yes, PHP is absolutely free, and it is an Open Source.It can be used under GPL.

Does PHP supports OOPs Features?
Yes, PHP is a full-featured server-side scripting language and enriched with Object Oriented Programming system approach. We can define a class, constructor. We can create Objects and can implement oops features like Abstraction, Polymorphism, Inheritance, and Encapsulation.

What is the difference between array_merge and array_combine?
We can differentiate between the two terms while understanding their definitions.
array_merge(): Merge Elements of arrays in a single array while preserving their indexes. But array_combine() returns a new array where values in one array are keys in new arrays and values of another array values in new arrays.

What is the Latest stable version of PHP and MySQL?
You should check these things before your Interview because the version the things are updating frequently.
For PHP: www.php.net
For MySQL: www.mysql.com

Spread the love

OOPS interview questions and answers

What is OOPS(Object Oriented Programming System)?
OOPS, that is Object Oriented Programming System is a modularized system of programming. Chunks of programs are designed in such a manner that we can reuse them, modify them and also can rework on them.


What is a class?
A class is a collection or a group to represent similar type entities having identical properties and behavior.A class does not exist in physical but a concept to visualize real-world entities.


What is an object?
An object is a blueprint of a class. It is a prototype what class defines. When we have a working object we can say it is an instance.

How can we differentiate between Procedural Programming System and OOPS?
An object-oriented language is based on modules that are Object but procedural programming has no such concepts.
OOPS is able to encapsulate data and member functions in a single block but procedural programming language represents a discrete structure.
A procedural language is based on top-down approach whereas object-oriented language is based on the bottom-up approach of the algorithm.
A procedural language is rigid in nature, but OOPS provide flexibility and reusability of code.

What are the basic pillars of OOPS?
Fundamental pillars of OOPS and are as follows:
1-Abstraction
Hiding the sensitive data or the way of implementation, but revealing the necessary data to the end user.It limits the scope of variables, methods.Abstraction is to implement the security features in OOPS and so in application.
2-Encapsulation
Encapsulation is the wrapping of data and data functions in a single block of codes. It contains the data definitions and behavior definition in a single block that is Class.
3-Inheritance
Inheritance provides flexibility features to OOPS. It allows a class to share its functions, variables to other classes and the classes that will be using the functions definitions and data variables of other class called child class, and this phenomenon is called Inheritance.
4-Polymorphism
Polymorphism is a way to reimplement the methods in child-class or in a subclass that is already implemented in the parent class.It gives flexibility to an object to represent it and to use its many forms as per the function definitions in classes.


What is a constructor in OOPS?
The constructor is a method which is called automatically when an Object of a class is instantiated.The constructor has the same name as that of the class and it does not return.


What is the basic difference between overloading and overriding?
Overloading
When two methods are defined with the same name in a single class but they must have different signatures, then this phenomenon is known as Overloading.
overriding
When a method defined in the parent class is reimplemented by subclass or child class, then this phenomenon is known as overriding.


Difference between class and an object?
A class is a definition and object is a prototype of that definition.An object contains states and behaviors and a class is a template of an object. An object is an instance of a class and it is working model of a definition that we can call a class.


What are the specifiers?
Specifiers or modifiers define the scope of variables and methods in OOPS.They implement a secure structure and access level in the architecture of an application.There is some important access specifiers are as follows:
Private:
Restricts the access to the class itself. Even Child or subclass are also not allowed to use private functions and data.
Protected:
A protected function or variable or member is accessible within the class and within the child class or subclass only. It cannot be accessible from anywhere else.
Public:
It provides an open accessibility to members. Either within the class or within child class or from anywhere in the script, It will be accessible.


What is a destructor?
the destructor is a function which can be called automatically when an object is deleted.

Spread the love

PHP array Interview Question and Answers

What is an array?
An array is a collection of data in a sequential manner. In PHP an array may hold many types of data.


How to define an empty array in PHP?
There are many ways to define arrays in PHP

1
2
$cars=[];
$cars=array();
How to check that a variable is an array in PHP?
There is library method to check, whether a variable is an array or not.
is_array($variable); – the function accepts a variable as a parameter and returns Boolean. If variable passed in it is an array it returns TRUE.


How to check the size of array?
We can find the size of an array using sizeof() function.


How many types of arrays are there in PHP we use?
Usually, there are three types of arrays in PHP:
1- Indexed Array
2- Associative array
3- Multidimensional Array
How can we add new value into an array in rum time?
We can do this using php method array_push(). There is another way we can simply assign new value to array and it will hold the next index. For example
1
2
3
4
5
$car=array(‘BMW’,’Benz’);
$car[]=’Toyota’;
$car[]=’Sujuki’;
?>
And finalil it will print: BMW,Benz,Toyota,Sujuki.
How can we remove a value from an array in PHP?
We can remove a value from an array in php using unset() method. We have to unset the index of that value.Suppose we have to delete ‘BMW’ from above array, then we have to unset the index of ‘BMW’ and tht is 0, so It will be as :
1
2
3
unset($car[0]);
?>
Demostrate foreach loop on a PHP array.
We are assuming that we have to print the name of cars in list using foreach loop. So we can do this as given in code snippet:
1
2
3
4
5
foreach($car as $key=>$value){
    echo “This a brand new “.$value;
    echo ”
“;
}?>
What will be the output when we execute the PHP code given below?
1
2
3
4
$array=array(1,2,3,4,5,6,7,8);
echo sizeof($array);
?>
OUTPUT:
Out of the above code will be the size of array. It will be 8.
How to sort an associative array in ascending order, according to the value?
We can use PHP library function asort(). This will sort the array in ascending order. In descending order, we will use arsort(). These functions return sorted arrays.
What is the function that we can use to remove the duplicate valuse from array in PHP?
PHP has array_unique() function to remove the duplicate values from array.
1
2
3
4
5
6
$fruits=array(“a”=>”mangow”,”b”=>”orange”,”c”=>”apple”,”d”=>”mangow”);
print_r(array_unique($fruits));
?>
?>
We aill get a list of uniq values.
How we can find an array of keys of another associative array?
Pass an associative array in function array_keys() and this will return an array of keys.
Spread the love