in Php

Introduction

Today we are going to talk about splat operator. You’re going to love this operator, If you are anything like me . This operator gives you a neat way to pass multiple parameters in a function. Ever heard about func_get_args() function in PHP. If not , let’s see a simple demonstration :

This is way better than using function sum( $a, $b, $c, $d ) , this should look fine but what about adding more parameters may be 10 . This is where func_get_args() plays a great part, this function was with us since PHP 5.5 .

This is all about Variable-length argument lists (Variadic functions), now since PHP 5.6 and later we can use splat operator instead of func_get_args(). This can be implemented using ( … ) triple dot. Let’s see a simple demonstration :

Neat right. 🙂

Argument Unpacking

Argument unpacking is performing reverse when passing arguments to a function using splat operators. Let’s look at the simple demonstration :

Easy and clean approach right 🙂 Happy coding 🙂