Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PHP Exercises : Print current PHP version

PHP : Exercise-17 with Solution

Write a PHP script to print current PHP version.

Note : Do not use phpinfo() function.

Sample Solution: -

PHP Code:

<?php
echo 'Current PHP version : ' . phpversion();
  // prints e.g. '2.0' or nothing if the extension isn't enabled
  echo phpversion('tidy')."\n";
?>

Sample Output:

Current PHP version : 7.0.15-0ubuntu0.16.04.4 

Flowchart:

Flowchart: Print current PHP version

Note: string phpversion (string $extension ): Returns a string containing the version of the currently running PHP parser or extension.

PHP Release History:

Version Release date Supported until
1.0 8 June 1995
2.0 1 November 1997
3.0 6 June 1998 20 October 2000
4.0 22 May 2000 23 June 2001
4.1 10 December 2001 12 March 2002
4.2 22 April 2002 6 September 2002
4.3 27 December 2002 31 March 2005
4.4 11 July 2005 7 August 2008
5.0 13 July 2004 5 September 2005
5.1 24 November 2005 24 August 2006
5.2 2 November 2006 6 January 2011
5.3 30 June 2009 14 August 2014
5.4 1 March 2012 3 September 2015
5.5 20 June 2013 10 July 2016
5.6 28 August 2014 31 December 2018
6.x Not released N/A
7.0 3 December 2015 3 December 2018
7.1 1 December 2016 1 December 2019
7.2 30 November 2017 30 November 2020

Beginning on June 28, 2011, the PHP Group implemented a timeline for the release of new versions of PHP. Under this system, at least one release should occur every month. More details: https://php.net/releases/

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to count number of lines in a file.
Next: Write a PHP script to delay the program execution for the given number of seconds.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



PHP: Tips of the Day

How to Sort Multi-dimensional Array by Value?

Try a usort, If you are still on PHP 5.2 or earlier, you'll have to define a sorting function first:

Example:

function sortByOrder($a, $b) {
    return $a['order'] - $b['order'];
}

usort($myArray, 'sortByOrder');

Starting in PHP 5.3, you can use an anonymous function:

usort($myArray, function($a, $b) {
    return $a['order'] - $b['order'];
});

And finally with PHP 7 you can use the spaceship operator:

usort($myArray, function($a, $b) {
    return $a['order'] <=> $b['order'];
});

To extend this to multi-dimensional sorting, reference the second/third sorting elements if the first is zero - best explained below. You can also use this for sorting on sub-elements.

usort($myArray, function($a, $b) {
    $retval = $a['order'] <=> $b['order'];
    if ($retval == 0) {
        $retval = $a['suborder'] <=> $b['suborder'];
        if ($retval == 0) {
            $retval = $a['details']['subsuborder'] <=> $b['details']['subsuborder'];
        }
    }
    return $retval;
});

If you need to retain key associations, use uasort() - see comparison of array sorting functions in the manual

Ref : https://bit.ly/3i77vCC