I am Learn.i.ng

Some handy PHP functions

One beautiful thing about PHP is how you can start building with basic knowledge then you refactor your codebases as you learn more. In this post, I will show how to use some functions that will reduce the number of lines you need to type to achieve your goals.

list($name, $gender, $age) = ["John Doe", "Male", 42];

How to efficiently loop through PHP array elements

Use case: you have an array of images to which you want to prepend a path to get the full URL to be sent as an API response.

$images = array("image1.png", "image2.png", "image3.png", "image4.png", "image5.png");

A traditional way of doing things will be looping through each element of the array, prepending the path to each element, pushing the modified element to another array and returning that array.