Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Frank de Jonge:
Array destructuring in PHP
May 01, 2018 @ 14:48:15

Frank de Jonge has a post to his site sharing some helpful hints around the use of arrays in PHP. In this quick post he covers some of the array "superpowers", list assignments and nested destructuring.

One of the things I like the most about JavaScript, and PHP also to some extent, is how flexible and expressive they CAN be (but not always are). I also believe that JavaScript, PHP, and Python have a number of features that make them a good fit for serving the forefront of the web.

[...] The most versatile type of PHP, to me, is the array. The array can be used to act like many different classic data types. You can use them as a List, a Set (although that requires some specific handling), a HashMap, just to name a few.

He starts with the "superpowers" that arrays gained in PHP 7.1 (the square bracket syntax for destructuring) and some code examples showing it in action. He then moves on to show how this update works for list assignment. He finishes up the list with a look at nested destructuring and referencing values from subarrays with this same square bracket syntax.

tagged: array destructure language square bracket php71 tutorial

Link: https://blog.frankdejonge.nl/array-destructuring-in-php/

Ian Barber's Blog:
Linear Regression in PHP
Oct 13, 2011 @ 17:57:09

Ian Barber has a new post about an interesting method for determining the "line" that results follow in your statistics - linear regression in PHP (complete with code samples).

There are a lot of problems that fall under predicting these types of continuous values based on limited inputs - for example: given the air pressure, how much rain will there be, given the qualifying times, how quick will the fastest lap be in the race. By taking a bunch of existing data and fitting a line, we will be able to make a prediction easily - and often reasonably correctly.

He defines two pieces of information, the intercept and the gradient, and how they relate to minimize the "square error" that can come from getting the square root of your values based on the difference between an actual and predicted value. Based on a sample data set, he comes up with these results, showing the trend line for the points given. He points out a few issues with the method and corrects them with a few tweaks to his original algorithm.

tagged: linear regression algorithm square error


Trending Topics: