I'm an intermediate programmer who works with PHP mostly. Recently, I noticed that many PHP developers use arrays as function arguments in their code. I'm little sceptic of using arrays like that, as some of the people in my workplace said that it's not the best practice.
For example, I have this piece of code in one of my WordPress projects right now, it might not make sense to you completely, but it's relevant:
<?php
/**
* Print a list of featured posts.
*
* @param $args Array Function Arguments
* @return $html String The final markup
*/
if( function_exists( 'abc_featured_posts_list' ) ) :
function abc_featured_posts_list( $args = array(
'number' => 8,
'image' => 'path/to/default.image',
'wrapper' => false,
'style' => 'minimal'
) ) {
// Storage for the list markup
$html = null;
...
...
return html;
}
endif;
?>
It's the first time I'm passing arguments like this in a PHP function. Is it the right way to do that? What is the advantage of using an array over a bunch of variables in such a case?