Why do you not use a Collection with TKey and TValue? 🤔 I think modern tools will support Generics, so that you can specify your index and your values. And it's a easy replacement for "array".
In PHP, Arrays "are" key-value collection under the hood. It's not an array in traditional sense. Which means that it exposes a lot larger functionality on data set. Therefore it is common practice to use design patterns similar to what the author has demonstrated, to minimize the exposed surface of data to users. This is the reason why Laravel has so many functions, they basically abstract the data behind, providing you individual APIs to manipulate/access the data, making sure its integrity is maintained. A similar approach was used by codeigniter, but they did allow direct access to data, so companies would make internal rules to use only framework functionality, to make sure integrity was maintained.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why do you not use a Collection with TKey and TValue? 🤔 I think modern tools will support Generics, so that you can specify your index and your values. And it's a easy replacement for "array".
In PHP, Arrays "are" key-value collection under the hood. It's not an array in traditional sense. Which means that it exposes a lot larger functionality on data set. Therefore it is common practice to use design patterns similar to what the author has demonstrated, to minimize the exposed surface of data to users. This is the reason why Laravel has so many functions, they basically abstract the data behind, providing you individual APIs to manipulate/access the data, making sure its integrity is maintained. A similar approach was used by codeigniter, but they did allow direct access to data, so companies would make internal rules to use only framework functionality, to make sure integrity was maintained.