Web Development & WordPress

Learning Plugins Development: Part 3

Here i am trying to create a custom WordPress plugin that generates a shortcode [post_title_with_pagination] to display post titles with pagination. This step-by-step guide will help you set up the plugin and use it in your WordPress site effectively. Please check Learning Plugins Development: Part 1 to find out the steps.

Continue reading “Learning Plugins Development: Part 3”
Web Development & WordPress

Sorting Arrays in PHP: rsort() and arsort() Functions Explained

This PHP script provides an example of how to use rsort() for reverse sorting and arsort() for reverse sorting while preserving the array keys.

<?php
echo "<pre>";
$reverseSort= array("a","d","e","b","c");
echo " <br> Main array <br>";
print_r($reverseSort);
rsort($reverseSort);
echo"<br>After rsort():<br>";
print_r($reverseSort);

$reverseSort1= array("a","d","e","b","c");
echo " <br> Main array <br>";
print_r($reverseSort1);

echo"<br>After rasort() which preserve keys :<br>";
arsort($reverseSort1);
print_r($reverseSort1);

echo "</pre>";
?>

OUTPUT

 Main array 
Array
(
    [0] => a
    [1] => d
    [2] => e
    [3] => b
    [4] => c
)

After rsort():
Array
(
    [0] => e
    [1] => d
    [2] => c
    [3] => b
    [4] => a
)
 
 Main array 
Array
(
    [0] => a
    [1] => d
    [2] => e
    [3] => b
    [4] => c
)

After rasort() which preserve keys :
Array
(
    [2] => e
    [1] => d
    [4] => c
    [3] => b
    [0] => a
)
Web Development & WordPress

Understanding PHP Spaceship Operator for Comparing Values

The spaceship operator (<=>) in PHP is used for comparing two values and returns -1, 0, or 1 depending on whether the first value is less than, equal to, or greater than the second value. Introduced in PHP 7, it simplifies comparisons and is especially useful for sorting functions.

CODE:

Continue reading “Understanding PHP Spaceship Operator for Comparing Values”