检查值是否存在 [英] check if value exists
本文介绍了检查值是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在代码点火器工作,
代码点火器有一个名为 table_exists() 的函数;
code igniter has a function called table_exists();
你向它传递一个表名,并且,正如预期的那样,它会检查数据库以查看它是否存在.
where you pass it a table name, and, as expected it checks the database to see if it exists.
我想做的是,
以表名开头
如果tablename存在,使用tablename1,如果tablename1存在使用tablename2等
if tablename exists, use tablename1, if tablename1 exists use tablename2 etc.
我的问题是,
最好的写法是什么?
推荐答案
$i = 1;
$table_name = 'table';
$table_name_test = $table_name;
while($this->db->table_exists($table_name_test)) {
$table_name_test = $table_name . strval($i);
$i++;
}
$tablename = $tablename_test;
确保使用完整的 $this->db->table_exists()
CodeIgniter 语法
Make sure you use the full $this->db->table_exists()
CodeIgniter syntax
这篇关于检查值是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文