How to create array-like data-structures with object keys in PHP?

g00fy1

New Member
I want create arrays with object keys in PHP, i.e. something like this: \[code\]<?php$keyObject = new KeyObject;$valueObject = new ValueObject;$hash = array($keyObject => $valueObject);\[/code\]However, this raises an error. Arrays may only have integer or string keys. I end up having to do something like: \[code\]$hash = array( 'key' => $keyObject, 'value' => $valueObject);\[/code\]This works but it's not as neat as I'd like. Is there a better way? (Perhaps something from the SPL that I'm missing...)TIA
 
Back
Top