PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

dbmopen> <dbminsert
Last updated: Sun, 25 Nov 2007

view this page in

dbmnextkey

(PHP 4)

dbmnextkey —

설명

string dbmnextkey ( resource $dbm_identifier , string $key )

Returns the next key after key .

매개변수

dbm_identifier

dbmopen()이 반환한 DBM 연결 식별자입니다.

key

The previous key

반환값

The next key if possible

예제

By calling dbmfirstkey() followed by successive calls to dbmnextkey() it is possible to visit every key/value pair in the dbm database. For example:

Example#1 Visiting every key/value pair in a DBM database

<?php

$key 
dbmfirstkey($dbm_id);
while (
$key) {
    echo 
"$key = " dbmfetch($dbm_id$key) . "\n";
    
$key dbmnextkey($dbm_id$key);
}

?>

참고



add a note add a note User Contributed Notes
dbmnextkey
fischer at schlund dot de
19-Mar-2001 10:08
When you have a key "0" or so in your DB, then the example don't works, because "while ($key)" will return false for 0 ...
I had good experiences with "while (strlen($key)>0)" as condition ... because when we have the last key false is returned and false evaluates to "nothing" ...
fred at ontosys dot com
12-Oct-2000 10:41
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);
}
?>

dbmopen> <dbminsert
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites