PHP 8.0 New Feature

Here is the list of new function in PHP 8.0


1. Match - This is kind of similar to switch operation. Here is the difference comparing with switch - 

$condition = 1;
$data =  match($condition) {
    1 => 'good', // this will return good if we print $data variable
    2 => print 'second' // this will print second and return 1 as print always return 1,
    3,4  => '3 or 4', // this will work if value of $condition is 3 or 4
    4 > 5 => 'checking', // we can add condition like this in match which was not possible in switch
    // so if $condition value is false than this condition will run as 4 > f is false
    default => 'default', // this one will return if any of the above conition is not met with $condition value
    // there has to be always a default condition in match statement otherwise it will give an error
    // while if switch default is not mandatory
}

echo $data; // we was able to assign match condition to a variable called $data and we can print return value like this.



Posted In:PHP


0 Comments


copyright forhad

Dev Laravel Blog | PHP 8.0 New Feature