note 9033 added to dbmnextkey

From: Date: Thu, 12 Oct 2000 14:41:08 +0000
Subject: note 9033 added to dbmnextkey
Groups: php.notes 
Request: Send a blank email to php-notes+get-6408@lists.php.net to get a copy of this message
dbmnext() seems to lose the thread if the program deletes keys as it walks through all rows. I imagine that something similar happens with inserts. One way around this is to make two passes: one to collect the keys and one to manipulate the rows. For example: $old_keys = array(); for ($key = dbmfirstkey($db); $key; $key = dbmnextkey($db, $key)) { $old_keys[] = $key; } while (list($_, $key) = each($old_keys)) { dbmdelete($db, $key); } http://www.php.net/manual/function.dbmnextkey.php

« previous php.notes (#6408) next »