note 9033 modified in function.dbmnextkey by felipe

From: Date: Tue, 22 Jul 2008 02:19:45 +0000
Subject: note 9033 modified in function.dbmnextkey by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142457@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: <?php $old_keys = array(); for ($key = dbmfirstkey($db); $key; $key = dbmnextkey($db, $key)) { $old_keys[] = $key; } while (list($_, $key) = each($old_keys)) { dbmdelete($db, $key); } ?> --was-- 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://php.net/manual/en/function.dbmnextkey.php

« previous php.notes (#142457) next »