Category: arrays

Understanding the Almighty Reducer

I was reently mentoring someone who had trouble with the .reduce() method in JavaScript. Namely, how you get from this: const nums = [1, 2, 3] let value = 0 for (let i = 0; i < nums.length; i++) { value += nums[i] } …to this: const nums = [1, 2, 3] const value = nums.reduce((ac, next) => ac + next, 0) Th...

Creating Strictly Typed Arrays and Collections in PHP

One of the language features announced back in PHP 5.6 was the addition of the ... token to denote that a function or method accepts a variable length of arguments. Something I rarely see mentioned is that it’s possible to combine this feature with type hints to essentially create typed arrays. For example, we could ...

Watch: Fundamental PHP Arrays and Array Functions in PHP

In this screencast I’ll walk you through 5 useful functions PHP provides to manipulate and extract data from arrays. Loading the player… jwplayer("video-5697").setup({ image: "https://d3rj1gznkm47xj.cloudfront.net/99c3273d-4693-4fed-9959-517bd2d3f9f7.png", sources: [ { file: "https...