note 104682 added to class.splobjectstorage

From: Date: Thu, 30 Jun 2011 13:57:03 +0000
Subject: note 104682 added to class.splobjectstorage
Groups: php.notes 
Request: Send a blank email to php-notes+get-181105@lists.php.net to get a copy of this message
I rewrote some scripts and changed object storage with arrays to SplObjectStorage. At some point I needed support of array_rand() but I did not find a function to return a random attached object of an SplObjectStorage object. So here is my solution for random access to SplObjectStorage: $o1 = new StdClass; $o2 = new StdClass; $s = new SplObjectStorage; $s->attach($o1); $s->attach($o2); $random = rand(0,$s->count()-1); $s->rewind(); for($i=0;$i<$random;$i++) { $s->next(); } var_dump($s->current()); ---- Server IP: 69.147.83.197 Probable Submitter: 77.186.164.237 ---- Manual Page -- http://www.php.net/manual/en/class.splobjectstorage.php Edit -- https://master.php.net/note/edit/104682 Del: integrated -- https://master.php.net/note/delete/104682/integrated Del: useless -- https://master.php.net/note/delete/104682/useless Del: bad code -- https://master.php.net/note/delete/104682/bad+code Del: spam -- https://master.php.net/note/delete/104682/spam Del: non-english -- https://master.php.net/note/delete/104682/non-english Del: in docs -- https://master.php.net/note/delete/104682/in+docs Del: other reasons-- https://master.php.net/note/delete/104682 Reject -- https://master.php.net/note/reject/104682 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181105) next »