Does PHP have symbols like Ruby? Or, should I just use strings as the keys in a PHP associative array?
I'm guessing it's the same answer as that of the question Is there a Python equivalent to Ruby symbols?
PHP has definable constants, but that's not really very useful in this context.
So no. Use strings as keys.
If your concern is the overload of using strings as array keys and the fact that the array is copied instead of passed as reference every time, I can suggest you to use stdClass
, that is basically an object class that can be modified dynamically, array-like, but it behaves as an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With