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]
– Edit
Here's Matt Staufer live coding some cool array / collection stuff
Join 9,500+ smart developers
Get my monthly newsletter with 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.
"I’ve been reading freeks newsletter for a while now, and it’s easily one of my favorite developer newsletters. Freek shares practical, no-nonsense insights from running Spatie, maintaining hundreds of open-source packages, and shipping real products. Every time I get useful Laravel tips, smart tooling advice, always high quality and immediately applicable."
– doeken.org - submitted by Doeke Norg – Edit
Yield better results by iterating over generators. Learn more about these supercharged arrays that can preserve memory.
Read more [doeken.org]
– stitcher.io – Edit
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]
– twitter.com – Edit
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]
– Edit
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