Skip to main content

Posts

How to create STAR PATTERN in PHP

STAR Pattern Printing using PHP for loop Pattern: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Code: for($i=0; $i<5; $i++) { for($j=0; $j<5; $j++) { print_r(" * "); } print_r("<br/>"); } Pattern: * * * * * * * * * * * * * * * Code: for($i=0; $i<5; $i++) { for($j=0; $j<=$i; $j++) { print_r(" * "); } print_r("<br/>"); } Pattern:              *          * *        * * *     * * * *  * * * * * Code: for($i=0; $i<5; $i++) { for($j=5; $j>=$i; $j--) { print_r("&nbsp; ");  } for($k=0; $k<=$i; $k++) { print_r("*"); } print_r("<br/>"); } Pattern: * * * * *    * * * *       * * *          * *             * Code: $temp = 1; for($i=5; $i>=1; $i--) { for($k=$temp; $...

6 guaranteed steps how to create CRON JOB FUNTION in wordpress

Create Cron Job function in Wordpress plugin Step 1: Register function on plugin activate  register_activation_hook(__FILE__, 'activate_one'); Step 2: add_filter function for interval //Filter for Adding multiple intervals add_filter( 'cron_schedules', 'intervals_schedule' ); // define interval function   function intervals_schedule($schedules) {   $schedules['everyminute'] = array(    'interval' => 60, // Every 1 minutes    'display'  => __( 'Every 1 minutes' )   );   return $schedules;  } Step 3: Activate hook function   //Schedule a first action if it's not already scheduled   function activate_one() {   if (!wp_next_scheduled('wpyog_cron_action')) {    wp_schedule_event( time(), 'everyminute', 'wpyog_cron_action');   }  } Step 4: Cron hook function   //Hook into that action that'll fire after 1 minutes   add_action('wpyog_cron_action', 'execute_...

Simple JavaScript Object and Class Examples

In JavaScript, most things are objects. An object is a collection of related data and/or functionality Namespace: Everything you create in JavaScript is by default global. In JavaScript namespace is Global object . How to create a namespace in JavaScript? Create one global object, and all variables, methods, and functions become properties of that object. Example:  // global namespace var MYAPP = MYAPP || {}; Explaination: Here we first checked whether MYAPP is already defined.If yes, then use the existing MYAPP global object, otherwise create an empty object called MYAPP How to create sub namespaces? // sub namespace MYAPP.event = {}; Class JavaScript is a prototype-based language and contains no class statement.JavaScript classes create simple objects and deal with inheritance. Example: var Person = function () {}; Explaination: Here we define a new class called Person with an empty constructor. Use the class keyword class Calculation {}; A class expr...

PHP Fresher Technical Interview Questions

PHP Fresher Technical Interview Questions Question : How to find out leap year? Answer:  A leap year is a calendar year containing one additional day. It has 366 days instead of the usual 365 days. function isLeapYear($year){   return ((0 == ($year % 4)) && (0 != ($year % 100)) || (0 == ($year % 400))); } var_dump(isLeapYear(2020)); Code Explanation: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. Question : How to find out Prime number? Answer:   Prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Function to check whether prime number or not function isPrimeNumber($num){ $flag = 0; for($i=2; $i<=$num/2; ++$i)     {         // condition for nonprime number         if($num%$i==0)   ...

PHP 7 Feautures

Performance Battle, PHP 7 vs. PHP 5 With virtually all updates, minor performance upgrades are to be expected. However, this time PHP brings a significant improvement over earlier versions making sheer performance one of PHP 7’s most attractive features. This comes as part of the “PHPNG” project, which tackles the internals of the Zend Engine itself. By refactoring internal data structures and adding an intermediate step to code compilation in the form of an Abstract Syntax Tree (AST), the result is superior performance and more efficient memory allocation. The numbers themselves look very promising; benchmarks done on real world apps show that PHP 7 is twice as fast as PHP 5.6 on average, and results in 50 percent less memory consumption during requests, making PHP 7 a strong rival for Facebook’s HHVM JIT compiler. Have a look at this infographic from Zend depicting performance for some common CMS and Frameworks. PHP 7 Syntactic Sugar PHP 7 comes with new syntax features. W...

MySql Indexing

MySql Indexing A database index is a data structure that improves the speed of operations in a table.INSERT and UPDATE statements take more time on tables having indexes where as SELECT statements become fast on those tables. The reason is that while doing insert or update, database need to insert or update index values as well. Indexes are a way to avoid scanning the full table to obtain the result CREATE TABLE person ( last_name VARCHAR(50) NOT NULL, first_name VARCHAR(50) NOT NULL, INDEX (last_name, first_name) ); So if your index has two columns, say last_name and first_name, the order that you query these fields matters a lot. This query would take advantage of the index: SELECT last_name, first_name FROM person WHERE last_name = "John" AND first_name LIKE "J%" Using Create statement CREATE INDEX techsudhir_age ON employees(emp_name, emp_age); Alter command to update index ALTER TABLE person  ADD INDEX (name); Removing Indexes DROP...

MySQL Examples for Beginners

MySQL Examples for Beginners This basic MySQL query which will help beginners to learn. -- Delete if it exists mysql> DROP DATABASE IF EXISTS databaseName -- Create only if it does not exists mysql> CREATE DATABASE IF NOT EXISTS databaseName -- Set the default (current) database mysql> USE databaseName -- Show the default database mysql> SELECT DATABASE() -- Show the CREATE DATABASE statement mysql> SHOW CREATE DATABASE databaseName  -- Show all the tables in the current database. mysql> SHOW TABLES; -- Create the table "products". mysql> CREATE TABLE IF NOT EXISTS products ( productID bigint(11) UNSIGNED NOT NULL AUTO_INCREMENT, productCode CHAR(3) NOT NULL DEFAULT '', name VARCHAR(30) NOT NULL DEFAULT '', quantity INT UNSIGNED NOT NULL DEFAULT 0, price DECIMAL(7,2) NOT NULL DEFAULT 0000.00, PRIMARY KEY (productID) ); -- Describe the fields (columns) of the "products" table mysql> DESCRIBE pro...