Author: Codereplica
To sort an array value there is function available in PHP.But i’ll show you the same things without using of in-built PHP function. First see array sorting in ascending order without in-built function: <?php $a=array(5,15,25,7); for($j = 0; $j < count($a); $j ++) { for($i = 0; $i < count($a)-1; $i ++){ if($a[$i] > $a[$i+1]) { $temp = $a[$i+1]; $a[$i+1]=$a[$i]; $a[$i]=$temp; } } } echo "Sorted Array is: "; echo "<br />"; print_r($a); // Output Sorted Array is: array(5,7,15,25); Now see the in-built function: sort() – sort arrays in ascending order rsort() – sort arrays in descending order asort() -…
Hooks are way to add or modifying the functionality or visuality of the site without altering the main/core code. There are 2 types of hooks,Actions and Filters.>> Actions are hooks that WordPress core launches at specific points during the page cycle during which we can add our own functionalities. Example : load a custom script file in the footer of the page. function mytheme_enqueue_script() { wp_enqueue_script( 'my-custom-js', 'custom.js', false ); } add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_script' ); >>Filters are similar to Actions, in that they occur during the certain points of a page loading. However they are used to intercept, manage and…
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.Such as – 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43…See the below code how to find or get all prime number in between 1 to 100 – <?php for($i=1;$i<=100;$i++){ //numbers to be checked as prime $counter = 0; for($j=1;$j<=$i;$j++){ //all divisible factors if($i % $j==0){ $counter++; } } //prime requires 2 rules ( divisible by 1 and divisible by itself) if($counter==2){ print $i." is Prime <br/>"; } } Explanation :Here i’m taking two ‘for…
An array is a special variable, which can hold more than one value at a time. To add or sum of array value we can use in-built function of PHP which is “array_sum” or by using of for loop. Firstly i’m going to show you how to add or sum of array value without in-built function. See the below code – <?php $a=array(5,15,25,7); $sum = 0; foreach($a as $key => $value) { $sum +=$value; } echo $sum; Explanation : In the above code i store an array value to $a variable and take $sum variable is equal to 0. After…
A leap year is a calendar year that contains an additional day added to keep the calendar year synchronized with the astronomical year or seasonal year.For example, in the Gregorian calendar, each leap year has 366 days instead of 365, by extending February to 29 days rather than the common 28. These extra days occur in each year which is an integer multiple of 4 (except for years evenly divisible by 100, which are not leap years unless evenly divisible by 400). As now all of you know that what is Leap Year.Now let’s see how it calculate or determine…
We read in math Odd and Even numbers that is Odd numbers are whole numbers that cannot be divided exactly into pairs and Any number that can be exactly divided by 2 is called as an even number. Example : Odd Number – 1, 3, 5, 7, 9, 11, 13, 15…… Even Number – 2, 4, 6, 8, 10, 12, 14, 16….. Before going to solution first lets see what is bitwise operator. Bitwise operators are used for manipulating a data at the bit level that is 0(zero) and 1(one). Basically there are two methods in bitwise operator that is “Bitwise AND(&) operator” and “Bitwise OR(|)…
We read in math Odd and Even numbers that is Odd numbers are whole numbers that cannot be divided exactly into pairs and Any number that can be exactly divided by 2 is called as an even number.Example :Odd Number – 1, 3, 5, 7, 9, 11, 13, 15……Even Number – 2, 4, 6, 8, 10, 12, 14, 16…..and it’s easy to say which is odd number or which is even number if number is small or below 100,but think if number is large such as in 4-5 digit (37987) it’s difficult to identify number type, let’s take you are little more genius and may be…
To store or get selected checkbox value for further use such as fetching or sending data from server may be there lots of way to do this,but after trying lots of method i found below code is perfect for this task.It’s easy,simple and few line code.I’m approaching this solution by using of jQuery, so let’s don’t waste a time and start copying below code make your task easy. function Populate(){ vals = $('input[type="checkbox"]:checked').map(function() { return this.value; }).get().join(','); console.log(vals); $('#adminRole').val(vals); } $('input[type="checkbox"]').on('change', function() { Populate() }).change(); Explanation: In the above code i create “Populate” method which will be always trigger whenever…