Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would I use a Hack dict over a PHP array?

The docs are pretty light. The interface looks almost identical to an array.

When should I prefer a dict?

like image 625
hurrymaplelad Avatar asked Feb 02 '17 19:02

hurrymaplelad


People also ask

What is a Darray PHP?

An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values. To create an array in PHP, we use the array function array( ) . By default, an array of any variable starts with the 0 index.

Are PHP arrays dictionaries?

There are no dictionaries in php, but PHP array's can behave similarly to dictionaries in other languages because they have both an index and a key (in contrast to Dictionaries in other languages, which only have keys and no index).


1 Answers

Arrays in php are meant to be both dictionaries and vectors. That's very confusing. Also in arrays, there is key coercion to integer. Which is more confusing.

Hack dicts are meant to remove the ambiguity and fix the problem with the keys.

like image 68
Pablo Alcubilla Avatar answered Sep 28 '22 18:09

Pablo Alcubilla