Hey there, I want to save an item to an array and use the isset() function to perform checks. PHP: public $array = [];public function fromCache(Item $item){ if (isset($this->array[$item])) { return $this->array[$item]; } else { $this->array[$item] = [...]; return $this->array[$item]; }} Obviously, that won't work since you can't set objects as keys (array_flip? lol?). All I want to do is have something that could be set as a key so that I could identify $item. I know you can set $item->tags as key, but that could create conflicts. Don't different items have a unique data such as entities have a unique entity ID for the session they're online?
I think that you think wrong. You want to cache an item and want to get it again? Why don't you just use a one-dimensional array which only contains your items? You can push these items easily without requiring any identifiable key. You can also get them with in_array($item, $this->cache){}. Why don't you use this way?
Thank you both! P.S: This is how an item stored in an array looks like. Code: !php/object "O:25:\"pocketmine\\item\\ItemBlock\":8:{s:8:\"\0*\0block\";O:20:\"pocketmine\\block\\Air\":7:{s:5:\"\0*\0id\";i:0;s:7:\"\0*\0meta\";i:0;s:11:\"boundingBox\";N;s:5:\"level\";N;s:1:\"x\";N;s:1:\"y\";N;s:1:\"z\";N;}s:5:\"\0*\0id\";i:0;s:7:\"\0*\0meta\";i:0;s:26:\"\0pocketmine\\item\\Item\0tags\";s:0:\"\";s:31:\"\0pocketmine\\item\\Item\0cachedNBT\";N;s:5:\"count\";i:0;s:13:\"\0*\0durability\";i:0;s:7:\"\0*\0name\";s:3:\"Air\";}"