Category Archives: PHP

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

What is Singleton Design Pattern?

Singleton pattern is a technique to provide a class global state. Once we have created the instance of the class we can use the existing instance multiple times. So it restricts the multiple instantiation of a class.It is a great example of re-usability in Object Oriented Programming System.

How it works?
We restrict the constructor while declaring it as private , of the class to access it from outside and a static method is created that returns the instance.

Example in PHP:

class SingletonClass {
  private static $the_instance = null;
  //the private constructor
  private function __construct()
 //public static function to return the instance
  public static function getInstance()
    if (self::$the_instance == null)
      self::$the_instance = new SingletonClass();
    return self::$the_instance;

Usage of Singleton Class:

Connecting A database and use exiting connection, to avoid multiple open connection issue:

	class DB {

	  private static $instance = null;
	  private $conn;
	  private $host = 'localhost';
	  private $user = 'root';
	  private $pass = 'password';
	  private $name = 'my_database_name';
	  private function __construct()
	    $this->conn = new PDO("mysql:host={$this->host};
	    dbname={$this->name}", $this->user,$this->pass,
	    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
	  public static function getInstance()
	      self::$instance = new DB();
	    return self::$instance;
	  public function dbConnection()
	    return $this->conn;

Now creating an Instance using the static method:

	$the_instance = DB::getInstance();
	$conn = $the_instance->getConnection();
Spread the love

Common Programming Interview questions and Answers

No, any technical interview can be completed without logical questions based on simple programming techniques. When you are going for a Programmer profile, you must know the simple logic applied to make complex programs. Here is the collection of such important logical questions asked in an interview.These collection includes reverse string,factorial,star printing pattern,swap,leap year,prime number,odd-even number,palindrome etc.


Write PHP script to reverse string without using any PHP function.

	function reverseString($string){
		return $output;
	$my_string="this is a string to be reversed";


Write a program to find Factorial Of a number without using recursion.

function findFactorial($n){
	$factorial = 1;
		return $factorial;
	}else if($n&amp;gt;1){
			$factorial = $factorial*($n-$i);

	return $factorial;

echo findFactorial(10);


Write a program to find Factorial of a number using recursion.

function findFactorialRec($number){
	if($number &amp;lt;= 1){    
        return 1;   
        return $number * findFactorialRec($number - 1);   
echo findFactorialRec(10);


Write a program to print the following Pattern

*  *
*  *  *
*  *  *  *
*  *  *  *  *

for ($i=1;$i&amp;lt;=$n;$i++){
	for ($j=0; $j &amp;lt; $i ; $j++) { 
		echo "# ";
	echo "&amp;lt;br&amp;gt;";
echo "&amp;lt;br&amp;gt;";


Write a program to print the following Pattern.

                             *  *
                          *  *  *
                      *  *  *  *
                   *  *  *  *  *

for ($i=1;$i&amp;lt;=$n;$i++){
	for ($j=$n-$i; $j &amp;gt; 0 ; $j--) { 
		echo "+";
	for ($k=0; $k &amp;lt; $i ; $k++) { 
		echo "*";
	echo "&amp;lt;br&amp;gt;";
echo "&amp;lt;br&amp;gt;";


Write a program to print the following Pattern.

                               * * *
                            * * * * *
                         * * * * * * *
                      * * * * * * * * *

for ($i=0; $i &amp;lt;$n-1 ; $i++) { 
		echo "+";
		echo "*";
	echo "&amp;lt;br&amp;gt;";
echo "&amp;lt;br&amp;gt;";


Write a function to check if a string is a palindrome or not.

function checkPalindrome($string){
		$mid = floor($length/2);
		for ($i=0; $i &amp;lt;=$mid; $i++) { 
			return "NOT A PALINDROM";
			return "PALINDROM";

$string ="ABCDEfEDCBA";
echo checkPalindrome($string);


Write a program to check whether a given number is prime or not:

function checkPrime($number){
			 	break ;
		echo "$number is a Prime Number";
		echo "$number is not a Prime Number";


Write a function to test a given year is Leap Year:

function checkLeapYear($year){
		echo "$year is a leap year";
   		echo "$year is not a leap year";


Write a program to swap two numbers without using any temporary variable.

function swapNumbers($a,$b){
	echo "Now A is $a and B is $b";


Write a program to check that a given number is odd or even.

function checkOddEven($number){ 
	if($number % 2 == 0){ 
		echo "$number is EVEN"; 
		echo "$number is ODD"; 


Spread the love

MVC Web Development Framework

What is Web Development Framework?

There is a huge number of server-side scripting languages, using them we can create web applications. Almost the scripts are full-fledged programming language and featured with Object Oriented Programming Systems. Popular of them are Java, PHP, Python, Ruby,Perl. At the early age of web the applications were built on conventional logic and components, are not organized or not reusable. As the next generation, web development technologies came into existence the requirement of frameworks increased.A need for such a tool was very important as they are time and cost efficient.

Now we have many frameworks with huge communities. Frameworks are the collection of basic building blocks and reusable code in an organized manner where maintenance and development both are painless processes. They implement code re-usability, inheritance, security, abstraction, accessibility, integrity, reliability, readability, maintainability in our applications. Now we are able to develop very robust applications in very less time. frameworks are enriched with various libraries and plugin. They also provide flexibility to extend the functionality of the core. Almost the framework is based on Model-View-Controller or MVC development pattern.

What is MVC?

MVC is a software architectural pattern, which provides a modular structure to an application and application is layered into Models(M), Views(V) and Controllers(C).


Model is a layer where all the data building logic is present. This layer is abstract from direct access. We write or database queries and fetch and format data in this layer with given parameters. This layer is a central layer of all three.


A view is a presentation layer. We see the desired results here in our browser. The user directly communicates with forms and perform actions and submit inputs. This is an end user layer where HTTP response displayed and request triggered by user actions.


A controller is an intermediate layer and create a pool between Model the data logic layer and View the representational layer. It collects user actions based on URI and parameters. Routing and reverse routing happen here.

Advantages of MVC Frameworks:

  1. Fast and quick development of complex web-applications.
  2. Collection of Plugins are available for most of the general purpose activities.
  3. Easy maintenance and debugging. Frameworks provide debugger kit , that eases the debugging process.
  4. MVC provides a modular structure to application that is why MVC based applications are flexible and robust.
  5. Most of them provide Database manipulation library, so no need to write custom and complex queries very often.
  6. Inbuilt security and migration features.
  7. Most of them come with a command-line interface to generate code-snippets and modules.
  8. They create SEO friendly URLs to easy for search engines to recognize your application urls.

What are the popular MVC framework based on PHP?

There are numerous MVC framework based on PHP. Some of them are as:
Laravel – Laravel is the most popular PHP framework with the latest release of PHP and suitable for heavy applications.It comes with Inbuilt Authentication and security features. Laravel has a powerful ORM and query builder. Laravel has a unique feature of artisan CLI tool.Blade template engine is used for presentation on view.

Zend Framework

Created by the developers of PHP.Zend Framework is a collection of professional PHP packages with more than 345 million installations. It can be used to develop web applications and services using PHP 5.6+, and provides 100% object-oriented code using a broad spectrum of language features. Zend Framework uses Composer as a package dependency manager; PHP Unit to test all packages; and Travis CI as a Continuous Integration service. Zend Framework also follows PHP-FIG standards and includes an implementation of PHR-7 for HTTP message interfaces (as shepherded by Matthew Weier O’Phinney, Zend Framework project lead).


CakePHP is a Rapid development framework written in PHP 5.6 and having a unique feature of Naming Convention. CakePHP has a powerful tool of bake console. We can create scaffolding within no time. It is suitable for Web services as well as small and heavy applications. We can use a template engine as well for the presentation layer.


This is a zero-configuration framework and mostly used for small scale application. It comes with all the features of OOPS and security parameters. It is fast ,and the most flexible among others in a group. Code-igniter has wonderful and organized documentation and a huge community over the web. Codeigniter also provide the feature of HMVC and templating.


Fastest growing over the internet and popular in recent years. Featured with MVC structure and can be used for small as well as heavy applications. It handles complex WSDL services easily.


Phalcon is a secure and well documented MVC framework. It is suitable for any type of applications. It has implemented with very high-security level.

Spread the love

20 Top Magento Interview Questions and Answers for Freshers

What is Magento?

Magento is an open-source e-commerce platform written in PHP.

Originally designed and developed by eBay and now used as the most popular eCommerce platform but now acquired by Adobe.

Magento has an optimal administrative area to manage all the eCommerce activities. Along with free edition, Magento also offers Enterprise solutions and market place to users.

Why Magento is preferred over other e-commerce platforms?

Magento is flexible and featured with all the security norms over the internet.

It is one of the best eCommerce platforms in terms of features, support, security. You can develop fully scalable and better eCommerce stores and market places using Magento.

Which PHP MVC framework, Magento is based on?

Magento architecture is based on the ZEND framework of PHP which is based on Model View Controller Concepts.

What is the latest version of Magento?

The current Stable version is Magento 2.3 as of 31 Dec 2018. Check for latest stable version:

What are the Basic features of Magento?

Some basic features of Magento are:

  1. Best catalog management interfaces compare to any other eCommerce.
  2. Based on MVC structure.
  3. Optimized for cross-selling, offers, coupon code, and gift card features to add.
  4. More flexible than any other eCommerce platform.
  5. Secured and optimized for the business purpose.
  6. Compatible with marketplace solutions.
  7. Inventory Control and Reporting features.
  8. Customer account and profile management.
  9. Compatible with almost the payment systems and shipping methods.
  10. 100% SEO friendly URLs.
  11. Suitable for multi-site, multi-vendors and multi-currency marketplace.
  12. Efficient order management system.
  13. Mobile and device compatible layout.
  14. Built-in support for API.

Is Magento Free?

Yes, Magento is an Opensource and Free for lifetime.

But Magento also offers Enterprise solutions and paid services and products.

What are the differences between Magento 1.9 and Magento 2.0?

  1. Magento 1.x is based on Legacy PHP whereas 2.x is based on PHP 5.5+ and PHP 7.x.
  2. Magento 1.x has an external Paypal plugin wherein 2.x Paypal is inbuilt.
  3. Magento 1.x based on JS prototype and 2.x is based on jQuery.
  4. Magento 2.x is featured with a new market place.
  5. Magento 2.x is decorated with a user-friendly Admin panel and Responsive in layout.
  6. Magento 2.x is enabled with full-page caching.

What is Inventory Management?

Inventory is the number of products in stock and ready to ship.

Inventory Management is a module available in both 1.x and 2.x version of Magento enables a seller to manage the inventory at the product level or Globally. It has interfaces to manage stock units very efficiently.

What is SKU?

SKU means Stock Keeping Unit this is the unique identification of a product in stock.

It helps to track product inventory from the warehouse to the delivery end.

A product in a store can be tracked using the Stock Keeping Unit.

There is no rule for creating SKU. It depends on the user and better to keep it as alphanumeric.

What is Page Layout Section?

According to Magento documentation “Magento is an object-oriented environment with pages that are assembled from separate components”.

A single HTML page layout is assembled with many layout components for example header, footer, menu, search box, subscription popup,menu-bar etc.few of them are reusable and few of them or particular to the view.

What is the product type that exists in Magento?

There are five types of products available in Magento:

  1. Simple Product
  2. Configurable Product
  3. Bundle Product
  4. Virtual Product
  5. Downloadable Product

What is Grouped Product or Bundled Product?

Grouped or a bundled product is a combo set of more than one product while a single product made-up of many products and has a fixed price.

Many Simple items are bundled to display as a grouped product. For example: Buy one Get One offer.

What is a Variable Product or Configurable Product?

Configurable or Variable product is a product available with variable properties addon options or customization options over a base product.

The price of the final product depends on addons added or the options selected. For example, Pizza with custom toppings and sizes, Thirst with colors and size, etc.

What is Tax Rule in Magento?

Tax rules incorporate a combination of product class, customer class, and tax rate. Magento provides an interface to define a tax rule for products.

Magento Calculated sum total applied all the axes defined in the rule.

What are the statics blocks?

Static blocks are the chunks of HTML code that remain unchanged all over the site.

What is the database that Magento supports?

Magento supports – MySQL as an RDBMS.

What are the advantages of Magento?

One-stop solution for the online market place.

  1. Designs and maintains by a world-class well-known eCommerce brand eBay, so it is well suited for eCommerce.
  2. Along with product and market, we can also manage the website as a very flexible CMS.
  3. Strong tools as Order management, Inventory management, Catalog management.
  4. SEO friendly HTML and URL.
  5. Featured with cross-selling and upselling.
  6. Rich security features.

What are the disadvantages of using Magento?

  1. Not suitable for a lightweight application, since heavy backend.
  2. Maintenance and development are expensive than those of others.
Spread the love

Laravel Interview Questions

What is Laravel?
Laravel is a PHP based web development framework and an Open Source.

It is the most popular MVC framework of the age and enriched with the latest technical specifications.

Laravel is different from other frameworks when it comes to performance because it has inbuilt security features, salable routing, flexibility.

What are Advantages of Laravel Framework?

Features of Laravel listed as :

  1. Supports MVC pattern of software development.
  2. Modular structure.
  3. Great Documentation and Number of forums.
  4. Dependency can be installed using composer tool.
  5. Easy to implement Authentication and Authorization.
  6. Inbuilt CSRF protection features.
  7. Powerful Artisan Command Line Interface.
  8. Featured with blade template engine, templates can be organize.
  9. Default Cache driver is configured and also support various cache drivers like Redis and Memcached.
  10. Debugging and use case features along with unit testing.
  11. Supports full-text search on Eloquent ORM modules.
  12. Schema Builder allows us to create database tables and migration.
  13. Best routing and session control features.

How can we install laravel via the composer?

Composer is a tool to install dependencies in any system.It is very easy to build dependency when we have to install third-party libraries.
Steps to install laravel using composer:
Step(1):Download and install composer from official website :
Step(2):Open CLI and run

composer create-project laravel/laravel test my-first-project

List some features of laravel 5.0 ?

Laravel is a powerful web development framework having features as :

  1. Laravel provide a modular structure to application which help us to build efficiently and ease the maintainability
  2. Includes features which help us to build test cases and debug the software and to meet the requirement.
  3. Laravel provide flexible routing feature to application, which leads to a better performance.
  4. Flexibility to run over many environment as local,production etc.
  5. Laravel is featured with ORM and Query Builder.It has rich library to query over complex conditions.
  6. It also maintains schema and build schema through PHP code.Help us to migrate the application.
  7. Laravel is also compatible to templating and uses Blade Template Engine.Blade is a Lightweight tempalting engine and provides hirerachical model to template designing.
  8. Laravel ease the methods of authentication and user management for application.

What is Artisan?

Artisan is a Command Line interface used by Laravel and It is very powerfull.It comes along with many powerful commands which help us to build scalable application modules in very less time.

List some artisan commands?

Some important artisan commands are listed:

  1. php artisan list : list all available artisan commands
  2. php artisan help migrate : display help screen for migrate command
  3. php artisan migrate –env=local : set the configuration environment as local
  4. php artisan –version : display the current version of laravel installation

What are Packages?

Packages are additional functionality which can be added to laravel easily.There are many types of packages which can be used according to requirement.

Name some of the packages used by Laravel?

List of some Laravel popular packages:

  1. Bootstrapper
  2. Laravel Schema
  3. Cashier
  4. Envoy
  5. Passport
  6. HTML
  7. EXCEL
  8. Scout
  9. Socialite
  10. IMAGE

What is routing?

Routing is a way to define flexible request URL for application. Laravel offers different routing methdods like get,post,put,delete,patch etc.

What is reverse routing in Laravel?

Reverse routing is a process to generate URL from the references given and route declaration at the time.

What is named routing in Laravel?

We can specify name for route, this is called Named Routing.We can access the name of a route that is running via the route name method.

What is database migration?

Laravel provide tools to migrate database tables from one server to another. We can create migration files. Migration has both import and rollback.A method up() is called to run the migration files and down() is called to rollback the changes.

How to create migration via artisan?

First of all we need to install migrate tools. Using this command we can install the migration tools.

php artisan migrate:install

artisan makes it very easy to create a migration:

php artisan migrate:make my_table_name

A migration file will be created for ‘my_table_name’ inside the application/migrations folder. We can execute all the migration using the following command line :

php artisan migrate application

How can we Rollback the last migration?

Run the artisan command to rollback the last migration:

php artisan migrate:rollback

How can we reset the migration?

Run the artisan command to reset the last migration:

php artisan migrate:reset

What are the Events in Laravel?

Events are the classes which are used to implement observer to listen the events triggered.Events are stored in app/Events folder.

What are service providers?

All the services need to be bootstrapped, so service provider perform this task in Laravel. According to Laravel official documentation “Service providers are the central place of all Laravel application bootstrapping. Your own application, as well as all of Laravel’s core services are bootstrapped via service providers”.(Laravel Official)

What is a service container?

Laravel official documentation says: “The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection.”(Laravel Official)

What is dependency injection in Laravel?

Dependency Injections pass the required dependency into an object externaly via constructor.

What are the Laravel Contracts?

Laravel’s Contracts are a set of interfaces that define the core services provided by the framework.

What are the Facades in Laravel?

In Laravel Facades are the classes that provide a “static” interface to classes that are available in the application’s service container. (Laravel Official)

How to enable query log in Laravel?

This is how you can enable query log in Laravel:



Must Read:  CakePHP Most Common Interview Questions and Answers

What is HTTP middleware?

As the name middleware is a common interface between request and response.
Middleware provide a convenient mechanism for filtering HTTP requests entering your application.
For example, Laravel includes a middleware that verifies the user of your application is authenticated.
(Laravel Official)


Must Read: Codeigniter Interview Questions and answers

What is CSRF protection?

CSRF or Cross-Site Request Forgery is an attack that may lead unwanted and harmful action. We need to secure state changing stions from attacks. Laravel provide inbuilt CSRF protection.

What are query scopes?

Query scope is feature developed by Laravel where we can reuse similar queries.We don’t need to write similar types of queries again in the application.Once the scope has been defined, you may call the scope methods when querying the model.(Laravel Official)

What are the soft deletes and how do we do soft deletes?

Soft delete is a technique to flag a record so that it can be ignored from selection and invisible in view, but still available in table.We can implement it using Eloquent Model which supports Soft Delete feature.

What are Eloquent models?

Eloquent ORM- Object Run Mapper – used to implement Active Record Pattern while interecting with database. It can also be used outside of Laravel.

What is query builder in Laravel?

Laravel’s database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application and works on all supported database systems. (Laravel Official)

How can we run custom and raw query in Laravel?

Calling raw() functions of DB class:

$result_data = DB::raw(‘SELECT first_name,email_id from users’);

Spread the love

What is New In CodeIgniter 4.x?

As we all know CodeIgniter is a PHP lightweight MVC framework.

It provides us fast, flexible, and secure techniques to develop PHP based applications.

The Codeigniter 4.x alpha and beta are released but the available version is not recommended for production use.

The flexibility of Codeigniter is maintained as usual along with the advancement of compatibility with PHP 7.


Core Features of CodeIgniter

  • CI is an MVC framework with a small footprint.
  • Codeigniter gives exceptional performance.
  • This is an MVC  framework with zero configuration.
  • No command-line configuration setup or dependencies installation to start(Optional).
  • CI is not restricted to any naming convention or coding rules.
  • No need to learn about advanced concepts like PEAR.
  • You do not need to learn template engine rendering. 
  • Simple, Clear and easy to understand documentation.

Features of Codeigniter 4.x

  1. The earlier versions of Codeigniter are based on PHP 5.6 or lower but the Codeigniter 4 will be featured with PHP 7.2 functionality and compatibility.
  2. It required the *intl* extension of PHP installed on the server.
  3. If we would like to use CURLRequest, we will need lib curl installed.
  4. Supported databases are:
    1. MySQL (5.1+) via the MySQLi driver
    2. PostgreSQL via the Postgre driver
    3. SqLite3 via the SQLite3 driver
  5. CodeIgniter 4 can also be used with command-line programs. As per the latest trend, most of the frameworks provide CLI usability and library. Since Codeigniter 4.x the framework will also be providing CLI interfaces for different purposes.
  6. The following PHP extensions should be enabled on your server: 
    1. Php-json
    2. Php-mbstring
    3. Php-mysqlnd
    4. Php-xml
  7. If you want to use CURLRequest in your CI application, you will need to install libcurl.
  8. The framework now provides for a public folder, intended as the document root for your app
  9. Hooks in Codeigniter are a great feature in is maintained and improved as well.

How to install Codeigniter 4?

Codeigniter 4 can be installed using many methods

  • In Manual Installation, you need to download the latest release from official site and can place it in your www directory after extracting it.
  • If you want to use the composer tool you need to install the composer first and then you can install using command line. Composer will also help you to add third-party plugins in your project in the future. You can download and install the composer from this link:
  • You can also clone the git repository of CodeIgniter.

Directory Structure for Codeigniter 4.x

A newly installed application has six directories:

  1. application
  2. system
  3. public
  4. writable
  5. tests
  6. Docs

Application Structure

  1. The framework still has app and system folders, with the same interpretation as before
  2. The framework now provides for a public folder, intended as the document root for your app
  3. There is also a writable folder, to hold cache data, logs, and session data
  4. The application folder looks very similar to that for CI3, with some name changes, and some subfolders moved to the writable folder
  5. There is no longer a nested application/core folder

The application directory i.e. app is the source code of your application. All the stuff done by you will remain here. The default structure of the app directory is as :


        /Config         Stores the configuration files

        /Controllers    Controllers determine the program flow

        /Database       Stores the database migrations and seeds files

        /Filters        Stores filter classes that can run before and after a controller

        /Helpers        Helpers store collections of standalone functions

        /Language       Multiple language support reads the language strings from here

        /Libraries      Useful classes that don’t fit in another category

        /Models         Models the database and business logic.

        /ThirdParty     ThirdParty libraries that can be used in application

        /Views          Views make up the HTML that is displayed to the client.

The above concepts will help you when you will doing any application on code igniter or you will be in CodeIgniter interview.

Spread the love

80 PHP functions asked in any Interview

This post contains the list of PHP functions that are frequently asked in various interview from freshers as well as experienced candidates. These are the parts of basic and core PHP. One must be familiar with these functions, I have just mentioned the definition in one line for each functions.They are frequently used in our application. Hope you will find this helpful.

  1. strlen() : returns the length of string passed.
  2. stristr() : returns rest of the string after the first occurence of a string in another string.
  3. stripos() : find the position of the first occurence of the string in another string.
  4. strip_tags() : returns string from html tags.
  5. strchr() : find first occurence of a string in another string and returns rest of the string.
  6. str_word_count() : returnd number of words in a string.
  7. str_split() : returns an array of charecters that string contains, when passed to it.
  8. str_replace() : search and replace a substring in a string by another substring.
  9. str_pad() : provide a virtual length to a string. It adds desired charecter to a string to make it up to required length.
  10. str_repeat() : Return a repeated string by a number of times.
  11. str_getcsv() : Parse a string to get the fields for CSV.
  12. rtrim() : remove white spaces from a string from right side.
  13. ord() : When we need to find ASCII value of the first charecter of the string we use ord().
  14. nl2br() : Conver all the new line charecters to BR tag of HTML.
  15. strstr() : returns rest of the string after the first occurence of a string in another string, find only case sensitive string.
  16. strtok() : breaks a strings into substrings
  17. strtoupper() : convert the case of string into uppercase.
  18. strtolower() : convert the case of string into lowercase.
  19. substr() : return a substring from a string of a length and from starting position.
  20. trim() : removes the white spaces from a string from left and right.
  21. ucfirst() : convert the case of first letters of all words in a string to uppercase.
  22. wordwrap() : break lines after a length.
  23. print() : output the result string when passed to it.
  24. print_r() : prints a resources ,object or an array along with the indexes.
  25. unlink() : delete a file from its location.
  26. unset() : set the value of a variable undefined.
  27. isset() : check whether the variable is defined or not.
  28. empty() : check whether an array is empty.
  29. array_chunk() : breaks an array into chunks of small arrays.
  30. array_combine() : combine two arrays of equal size where one is used for keys and another one is used for values.
  31. array_count_values() : count and returns the number of values of an array
  32. array_diff() : returns an array having difference between two arrays.
  33. array_flip() : flip key and value simultaneously.
  34. array_filter() : filter the values of an array based on a callback function.
  35. array_key_exists() : returns true if a key exists in an array.
  36. array_keys() : returns the array of keys from an array.
  37. array_map() : apply some operation on each value of an array and return a new array with modified values.
  38. array_merge() : merge the values of two array while retaining their keys.
  39. array_merge_recursive() : merge multidimensional arrays.
  40. array_push() : add a new value in an array at the end.
  41. array_rand() : select some random keys from an array.
  42. array_replace() : replace values in an array from the values in another array.
  43. array_reverse() : reverse the order of array and return new array.
  44. array_search() : search a value in an array and return the key of the value.
  45. array_shift() : remove the first element in an array.
  46. array_sum() : sum up all the values in an array.
  47. array_unique() : remove all the replicated values in an array.
  48. array_values() : returns an array of values with numeric index.
  49. array_walk() : Go to each value and run over an user defined function.
  50. array_walk_recursive() : Does the same recursively for an array.
  51. compact() : The compact() function creates an array from variables and their values.
  52. asort() : Sort an array values in ascending order.
  53. arsort() : Sort an array values in descending order.
  54. in_array() : returns true if a value find in an array.
  55. key() : return the key from the current pointer position.
  56. krsort() : sort and array based on keys and in descending order.
  57. ksort() : sort and array based on keys and in ascending order.
  58. range() : create an array from the range passed to it.
  59. date_create() : create a new dateTime object.
  60. date_create_from_format() : Create a user defined date from given format.
  61. date_diff() : returns difference between two dates.
  62. date_sub() : suntracts some period of time from a given date.
  63. date() : output the current date and time based on parameters given to it.
  64. gettimeofday() : output current time.
  65. gmmktime() : output UNIX time for GMT.
  66. localtime() : returns local time as UNIX timestamp.
  67. strtotime() : convert a string having datetime information into UNIX date.
  68. time() : eturn the current time.
  69. ceil() : returns the next interger value of the floating number passed to it.
  70. floor(): returns the next lowest integer value
  71. abs() : returns the absolute value passed to it.
  72. base_convert() : convert the base of number system.
  73. is_nan() : check whether a value is Not a Number.
  74. is_infinite() : check wherther a value is Infine.
  75. max() : find the max value from an array.
  76. min() : find minimum value from an array.
  77. mt_rand() : based on Mersenne Twister algorithm creates a random number.
  78. rand() : generate a random number
  79. round() : returns a floating point number up to a particular place of decimal point.
  80. sqrt() : returns the square root of the value passed to it.

Read More :

Top 10 Interview Questions and Answers for PHP freshers

PHP array Interview Question and Answers

Most Common PHP-MySQL Interview Questions and Answers

Spread the love

Hooks in CodeIgniter

In code igniter hooks are the points before and after the execution where we can call some specific functions.

These functions are called hooks and points where we call hooks are called hook points.

Hooks in Codeigniter are useful when we have to make some changes throughout the application, then we can do this without hacking all the files, just adding one hook at the appropriate point.

We can modify the way of usual rendering in code igniter application.

So hooks facilitate modification in functionality without changing the core.

Hooks in Codeigniter is important part of any Codeigniter Interview.

How we can use a hook in the Codeigniter framework?

Before we use any hook in application we need to enable the hook in config.php file. Set the enable_hook config variable: TRUE,

$config['enable_hooks'] = TRUE;

The Codeigniter framework provides the number of Hook Points to ease the development and modification in the application:

The pre_system is called very early during system execution.

Only the benchmark and hooks class have been loaded at this point.

As per the name just called before any of your controllers being called.

When all the base classes are loaded, routing and security checks are done a pre_controller hook is called.

The hook is called just after the controller class instantiated but none of the methods is called.

Called immediately after your controller is fully executed.

We have the _display() function in our core and we use it to render our view on the browser after the execution of all programs.

display_override allows use to display our own content at desired places.

$this->CI => get_instance();

We can call our own function instead of _display_cache() function using the cache_override hook. We can define our own cache display mechanism.

At the end of the system execution when final rendering is done post_system is called.

Define a hook :
A hook is defined in the hooks.php file located at application/config

Example of define a pre_controller hook:

$hook['pre_controller'] = array(  
            'class' => 'Classname',  
            'function' => 'functionname',  
            'filename' => 'filename.php',  
            'filepath' => 'hooks',  
            'params' => array('element1', 'element2', 'element3')  

The Hooks in Codeigniter will boost your learning  Codeigniter.

Spread the love

WordPress Dashboard – Tutorial 4

Admin Login
  • Give the user name and password .
  • Check the remember box as the browser will remind the login and password next time.
Dashboard area contains the following main tools and links:
  • Welcome section
  • Main menu(side menu)
  • Top menu
  • Admin area
  • Screen option
  • Help option
  • Quick draft section
  • At a glance section
  • Activity section
Welcome Section
  • This section has some important links which used frequently.
  • We can customize our site look as we click on Customize Your Site button.
  • Direct links to add an about page, to write the first blog.
  • We can turn on/turn off comments by external user on our posts from here.
  • We can visit our menu and widget systems from the link given.
Screen Options:
  • Screen option shows a group of check boxes.
  • Each check box is for a particular section.
  • If it is checked the section is on the screen on the dashboard .
  • Unchecked boxes hide the section from dashboard.
  • Ex – we have to hide the Welcome section from screen. We will uncheck it.

Spread the love

WordPress Installation : Tutorial 3

WordPress Installation
Before install a WordPress we should ensure that we have already created a database , where we have to create the WordPress tables with a prefix name .Default is prefix is wp_. We should have the following information as we are going to install the WordPress:
  • Database Name: wordpress
  • User name: root
  • Password: by default blank
  • Hostname:localhost


  1. Put
    the database name as you have created in the database field. It
    appears “wordpress
    by default.
  2. Give
    the mysql user name, which is root
    by default.
  3. Give
    the password of mysql , if you have’n define , then let the
    password field blank.
  4. Give
    the host name as running on default port, localhost.
  5. Give
    a prefix for the table name , which are being install in database.

A wp-config.php file is created, containing the information about database, username, password etc, at the time of installation.

Spread the love

WordPress Minimum Requirement : Tutorial 2

Chapter:2-Before Installation
Minimum Requirement of a system to run the WordPress
  • We need a server to run the PHP script, because PHP is a server side
    script and WordPress is based on PHP.
  • WAMP Server which is-Windows Apache MySQL PHP
  • Download Source code of WordPress from:
  • Latest  version of WordPress is wordpress-3.8.1 (as on 03-04-2014)
  • Latest of WAMP is 2.2 having
    • Apache 2.2.22
    • Mysql 5.5.24
    • PHP 5.3.13
    • PhpMyadmin
  • Apache is an open source web server , which is available in free. Apache is the one of the most popular and the most lovable web server by the web developers across the world.Separately we can download from:
  • MySQL is the most preferred open source RDBMS .
  • Very identical to MSSQL and other RDBMSs.
  • PHP(PHP Hypertext Preprocessor) is an open source server side scripting language having the features of OOPS and syntax similar to C
    Programming and Perl.
  • PHP provide a rich library to manipulate data and make most of the
    complicated data operations easy.
Spread the love

WordPress Inroduction : Tutorial 1

  • WordPress is a world famous Open Source CMS. Based on PHP as an open source server side scripting language.
  • WordPress is a free and open source blogging tool and a content management system (CMS) based on PHP and MySQL, which runs on a web hosting service.Features include a plug-in architecture and a template system.
  • WordPress is used by more than 18.9% of the top 10 million websites as of August 2013. WordPress is the most popular blogging system in use on the Web, at more than 60 million websites.
  • Architecture of template:
  • WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on millions of sites and seen by tens of millions of people every day.
  • It was first released on May 27, 2003, by its founders, Matt Mullenweg and Mike Little,as a fork of b2/cafelog. As of February 19, 2014, version 3.8 had been downloaded more than 20 million times.The license under which WordPress software is released is the GPLv2 (or later) from the Free Software Foundation.
Content Management Bystem (CMS)
  • A Computer Application that allows publishing, editing and modifying content  as well as maintenance from a central interface.
  • CMSs are often used to run websites containing blogs, news, and shopping. Many corporate and marketing websites use CMSs. CMSs typically aim to avoid the need for hand coding but may support it for specific elements or entire pages.
  • The function and use of content management systems is to store and organize files, and provide version-controlled access to their data. CMS features vary widely. Simple systems showcase a handful of features, while other releases, notably enterprise systems, offer more complex and powerful functions. Most CMS include Web-based publishing, format management, revision control (version control), indexing, search, and retrieval. The CMS increments the version number when new updates are added to an already-existing file.

Architecture of wordpress template:


Spread the love

CakePHP Advance : Most Common Interview Questions and Answers

What is HMAC?
HMAC means Hash-based Message Authentication Code . This is a authentication code used with combination of an encryption key and a hash function.What is Asset.cacheTime ?
Asset.cacheTime sets the asset cache time. This determines the http header Cache-Control’s max-age, and the http header’s Expire’s time for assets.What is DSN?
DSN is Data Source Name. A connection string format that is formed like a URI. CakePHP supports DSN’s for Cache, Database, Log and Email connections.What is PaaS?
Platform as a Service. Platform as a Service providers will provide cloud based hosting, database and caching resources. Some popular providers include Heroku, EngineYard and PagodaBox.

How we can use Cache in CakePHP?
Caching in CakePHP is facilitated by the Cache class. This class provides a static interface and uniform API to interact with various Caching implementations.

What types of Caching Engine does CakePHP provide?
1-FileCache-uses files.
2-ApcuEngine – uses the PHP APCu extension.
3-Wincache – uses the Wincache extension.
4-MemcachedEngine – uses the Memcached extension.
5-RedisEngine – uses the phpredis extension.

What is the default cache file path?
Path to where cache files should be saved. Defaults path is system’s temp dir.

How to read a Cache Object in CakePHP?
Using Cache class we can read the object as given below:


How to write a Cache Object in CakePHP?
Using Cache class we can write the object as given below:


How to remove an object completely from Cache?
Using Cache class we can delete the object as given below:


Can we read,write and delete multiple objects at a time?
Yes , we can do cache operations on multiple objects using functions like:


What is difference between Cache:clear() and Cache::delete() ?
Cache:clear() removes the values from associated with keys and empty them to hold new values, where as Cache:delete() removes the object completely from cache.

How can we disable or enable cache glaoblly in CakePHP?
We don’t need to disable all Cache read & writes and to expiration. We can do this using enable() and disable():


What are the different log levels in CakePHP?
1-Emergency: system is unusable
2-Alert: action must be taken immediately
3-Critical: critical conditions
4-Error: error conditions
5-Warning: warning conditions
6-Notice: normal but significant condition
7-Info: informational messages
8-Debug: debug-level messages

What is CakeRequest?
CakeRequest is the default request object used in CakePHP. By default, CakeRequest is assigned to $this->request, and is available in Controllers, Views and Helpers.

What are different ways to access the parameters in CakePHP?
Following ways :


How can we access the Passed Argumets from URI in CakePHP?
Way to access the Passed Argumets in CakePHP as:


How can we access the Named Parameters from URI in CakePHP?
Way to access the Named Parameters in CakePHP as:


How can we read Query String Parameters?
We can read these paameters using Cake Request Handler :

  // url is as : /posts/index?page=1&sort=title

How can we detect the request type?
We can check any request as :


How to detect environment in CakePHP?

    array('env' => 'REQUEST_METHOD', 'value' => 'POST')

How to detect pattern value in CakePHP?

    array('env' => 'HTTP_USER_AGENT', 'pattern' => '/iPhone/i')

How to detect options in CakePHP?

$this->request->addDetector('internalIp', array(
    'env' => 'CLIENT_IP',
    'options' => array('', '')

How to detect callback in CakePHP?

    array('callback' => function ($request) {
        return isset($request->awesome);

How to find the root directory of the the application?

How to find the base path in CakePHP?

How to find the full address of the current request in CakePHP?

Spread the love

CakePHP Advance Interview Questions and Answers For Experienced and Freshers

(1). What is the default cache Engine in CakePHP?
File Engine is the default cache Engine in Cake PHP.

(2). How many types of cache does CakePHP Support?
Different types of cache supported by CakePHP:

(3). How mamy types of Associations are there in CakePHP Models?
There are four association types in CakePHP:
Relationship Association type Example
one to one hasOne A user has one profile.
one to many hasMany A user can have multiple recipes.
many to one belongsTo Many recipes belong to a user.
many to many hasAndBelongsToMany Recipes have, and belong to, many ingredients.

(4). How to create association?
Model association example:

class Toy extends AppModel {
    public $hasOne = 'Profile';
    public $hasMany = array(
        'Toy' => array(
            'className' => 'Toy',
            'conditions' => array('Toy.approved' => '1'),
            'order' => 'Toy.created DESC'

(5). How to create Pagination in List view?
Cake PHP has a built in component ‘Paginator’. We can use this Component to create Pagination.

(6). How to destroy an association?
Use ‘unbindModel’ to destroy a particular type of association.

        array('hasMany' => array('Follower'))

(7). Give an example of LEFT JOIN using CakePHP ORM?
LEFT JOIN example using cake php ORM:

$options['joins'] = array(
    array('table' => 'channels',
        'alias' => 'Channel',
        'type' => 'LEFT',
        'conditions' => array(
            ' = Item.channel_id',
$Item->find('all', $options);

(8). How to prevent the default View and Layout to be rendered?
We can set the default view and default Layout variable to false.

$this->autoRender = false;

(9). What is layout in CakePHP?
View files that contain presentational code that wraps many interfaces in your application. Most views are rendered inside a layout.

(10).  What Is A Component In Cakephp?
Components are packages shared between controllers. They are useful when a common logic or code is required between different controllers.

(11). What are Components Used in Cakephp?
3-Access control lists
7-Request handling

(12). What Is A Behavior?
Behaviors in CakePHP are associated with Models.Behaviors are used to change the way models behaves and enforcing model to act as something else.

Spread the love

CakePHP Interview Questions and Answers

What is CakePHP ?
CakePHP is an open-source free web framework based on MVC pattern and written in PHP scripting Language for rapid web development.

What is MVC in CakePHP?
Model view controller (MVC) is an architectural pattern used in software engineering.
Model: Handle database related functionality, manipulating database related query like add, edit , delete.
View: Design parts written here (HTML+PHP)
Controller: Business Logic goes here

What are controllers?
A controller is used to manage the logic for a part of your application. Most commonly, controllers are used to manage the logic for a single model. Controllers can include any number of methods which are usually referred to as actions. Actions are controller methods used to display views. An action is a single method of a controller.

List some features of CakePHP framework ?
Top features of CakePHP framework

  1. MVC Architecture
  2. Zero configuration
  3. Inbuilt validation
  4. ACL Functionality and Security
  5. CRUD scaffolding
  6. Easily extendable with plug-ins
  7. Quick and flexible

What are Hooks in CakePHP?
CakePHP hooks are callback functions that are called before or after a model operation and defined in models.
List of some Hooks functions provided by CakePHP.

  1. beforeFind
  2. afterFind
  3. beforeValidate
  4. afterValidate
  5. beforeSave
  6. afterSave
  7. beforeDelete
  8. afterDelete
  9. onError

What is default function for a controller?
function index() is default function in controller.

What is a Element?
Element in cakephp are smaller and reusable bits of view code. Elements are usually rendered inside views.

What Is Scaffolding In Cakephp?
Scaffolding is a technical way that allows a developer to define and create a basic application that can create, retrieve, update and delete objects.

How To Get Current URL In CakePHP?
Simple using the following bit of code:


How can you make urls search engine friendly while using cakephp?
It’s an automatic task that is done by cakephp.

How cakephp URL looks in address bar?

What is Composer? How to create a CakePHP Project using Composer?
Composer is a tool for managing project dependencies. You can create a CakePHP project using Composer by running below commands on terminal.

php composer.phar create-project --prefer-dist cakephp/app my_app_name

How To Get Controller Name In CakePHP Views?
Get controller name in CakePHP:


What is a Helper in CakePHP?
Helpers in CakePHP are associated with Presentation layers of application.Helpers mainly contain presentational logic which is available to share between many views, elements, or layouts.

What are are drawbacks of cakephp?.
The learning curve, and it loads full application before it starts your task. Its not recommended for small projects because of heavy structure.

What is the name of Cakephp database configuration file name and its location?
Default file name is database.php.default.
Its located in “/app/config/database.php.defaut”

What is habtm?
Has And Belongs To Many is a kind of associations that can be defined in models for retrieving associated data across different entities.

List some database related functions in cakephp.
find, findAll , findAllBy , findBy , findNeighbours and query.

Spread the love

Top 10 Codeigniter Interview Questions and Answers for Experienced

1- What is hook?
CodeIgniter’s Hooks feature modify the core functionalitis of the framework without changing the core files. For example, If you want to run a script right before your controllers get loaded, or right after or at any other location, you can use Hook.
2- How many types of hooks are there in Code Igniter?
There are 7 availabe hook points:
pre_system :
Called very early during system execution. Only the benchmark and hooks class have been loaded at this point. No routing or other processes have happened.
pre_controller :
Called prior to controllers being called. All base classes, routing, and security checks have been done.
Called after controller is instantiated, but prior to any method calls happening.
Called after the controller is executed.
Overrides the _display() method, used to send the finalized page to the web browser at the end of system execution. This permits you to use your own display methodology. Note that you will need to reference the CI superobject with $this->CI->get_instance() and then the finalized data will be available by calling $this->CI->output->get_output().
Enables you to call your own method instead of the _display_cache() method in the Output Library. This permits you to use your own cache display mechanism.
Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.
Creating a hook :
‘class’ => ‘YourClassname’,
‘function’ => ‘your_function_name’,
'filename' => 'your_filename.php',
‘params’ => array(‘p1’, ‘p2’)
'filepath' => 'hooks',  
$hook[‘pre_controller’] = $my_hook;

3- Can we use multiple call to same hook?
Yes , we can use multiple call to same hook. Then We have to use multidimentional array:
$hook[‘pre_controller’][]= $hook_one;
$hook[‘pre_controller’][]= $hook_two;
4- What are the benifites of using hook in an application?
-We can modify core functionalitis without touching the core files.
-We can generate derired output without changing the view files.
-we can make a hook for recurring calls , like including footer and header in each function, without calling them in each controller function.
-we can create a script to minify the code before excecution take place.
-We can easily implement security checks, privacy, session, cache using hooks and can seperate these implementation from the main functionalitis.
5- WHat is HMVC?
HMVC is a Modular version of MVC. In this system we can implement modules for particular purpose. We may have put out controller , views and model in different modules. All these modules will be available in modules folder in application. HMVC stands for Hierarchical Model View Controller.
6- What is a module?
A module is a part of application and a full featured block which is implemented on HMVC pattern. A module contains its own Model, View and Controller. Although these resources can be shared with other modules.
7- What is difference between Library and Helper?
A CodeIgniter helper is a set of related global functions, you can call them any where in application. Once you load the helper file you can directly call the function. Basically the helper is procedural.
But a Library is a class, which you need to make an instance of the class. Once the library is loaded, we need to use $this operator to call the Library function. This is Object Oriented.
8- What is Routes in Code Igniter Framework?
Routing is the communication between URI and Controller. Routing decides the controller calls and parameters in code igniter. We can overwrite the routing rules in routes.php file.
9- How to use or enable libraries CodeIgniter?
We can initialize the library in controllers as given below:
10- Why CodeIgniter is a loosely coupled mvc framework?
CodeIgniter is called a loosely coupled mvc because, it provides unlimited flexibility to developers. It allows us to write and execute our custom codes, library, helpers. We can use call model and controllers functions in views and also can write custom code on views. It works like a core php when some one is going to manipulate it and on the other side it provide a modular structure to our application, XSS and CSRF functionalitis. It provides us lots of inbuilt library and also compatible with many more custome libraries. It never restricts us to write and execute any code.
Spread the love