PHP/MYSQL

Revisiting PHP Part VI: Unlimited arguments to PHP7 functions & Directory Levels in the dirname() function

The new Php 7 is shipped with a tidier algorithm to transfer a myriad of values to a PHP function despite the fact that there was provision for this in earlier versions. However, PHP7 now incidents with a better and calm way to really grasp the feature.

 

Let’s take a typical instance:

<?php

function get_the_sum(int …$integers){

return array_sum($integers);

}

echo get_the_sum(1,3,4,5,3,7,8); # outputs: 31

?>

 

Directory Levels in the dirname() function

Next, we take a look at the dirname() function, which is one of the most applied function of all time. It usually, on call returns the root directory by allowing the root of the real time file or directory as a string.

Additionally, this method now has the feature to give back paths of different levels. It is now possible to have access to another layer of any root directory to be given just by including the specific layer integer as a succeeding argument to the method.

Below is a typical description.

<?php

echo dirname(‘C:/**/**/**/DirLevelsdirfunc.php’, 2), PHP_EOL;

# outputs C:/**/**

 

?>