How do arrays work?
This post dives into the technical details of the array and figure out how you might invent the array yourself.
Read more [nan-archive.vercel.app]
Posts tagged with arrays
This post dives into the technical details of the array and figure out how you might invent the array yourself.
Read more [nan-archive.vercel.app]
Here's Matt Staufer live coding some cool array / collection stuff
Join 9,500+ smart developers
Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
– doeken.org - submitted by Doeke Norg
Yield better results by iterating over generators. Learn more about these supercharged arrays that can preserve memory.
Read more [doeken.org]
PHP Hero Brent Roose clearly explains the difference between array_merge and the + operator.
PHP has several ways of combining two arrays into one. There's a subtle difference between two methods though, a difference worth knowing.
Read more [stitcher.io]
Small #PHP tip: Want to before sure multiple keys of an array are set? Define them in one isset() call, it's so much clearer!
— Frank de Jonge (@frankdejonge) February 12, 2018
if ( ! isset($a['q']) || ! isset($a['w']) || ! isset($a['e'])) {
// PANIC
}
# Becomes
if ( ! isset($a['q'], $a['w'], $a['e'])) {
// OH NO!
}
Read more [twitter.com]
Tim Bezhashvyly recently wrote an article in which he explains an interesting approach to make sure all items in array are of a certain type. It leverages variadic functions which were introduced in PHP 5.6
Consider this piece of code (borrowed from Tim's post):
function foo (Product ...$products )
{
/* ... */
}
In PHP 7 you can even using the scalar types, such as string and int, to make sure all elements are of that type.
Read Tim's full article here: https://thephp.cc/news/2016/02/typed-arrays-in-php