PHP Implode值

时间:2019-02-13 03:12:48

标签: php implode

如何从下面的数组中获取单个值?当前第19行的结果就像19重复两次一样;

E:/ database / users / 1919 /

我只需要19,所以URL看起来像;

E:/ database / users / 19 /

<?php
$db = new SQLite3('C:/inetpub/wwwroot/database.db');
$row = $db->query('select id from users');
while ($lastrow = $row->fetchArray())
{
$id = implode($lastrow);
}
$database = 'E:/database/users/'.$id.'/';
?>

2 个答案:

答案 0 :(得分:3)

SQLite3Result::fetchArray默认使用$query = $this->db->get(); if ( $query->num_rows() > 0 ) { $data = array(); $data['row'] = $query->result_array(); $data['total_records'] = $this->db->count_all_results('shop'); $data['per_page_records'] = $query->num_rows(); return $data; }else{ return array('row'=>array(),'total_records'=>'0','per_page_records'=>'0'); } 模式,该模式返回所选列的0索引关联数组。

这意味着您将收到类似以下的值:

SQLITE3_BOTH

要解决此问题,您只需更改$lastrow = array( 0 => '19', 'id' => '19' ); 即可使用fetchArraySQLITE3_NUM检索单个值。

SQLITE3_ASSOC

或者,您只需指定要检索的列名,而不用使用$row = $db->query('select id from users'); while ($lastrow = $row->fetchArray(SQLITE3_NUM)) { $id = implode($lastrow); //list($id) = $lastrow; //alternative to implode } $database = 'E:/database/users/'.$id.'/';

implode

由于似乎只需要最后一行,所以我建议更改查询以提高整体性能。

$row = $db->query('select id from users');
while ($lastrow = $row->fetchArray()) {
    $id = $lastrow['id'];
}
$database = 'E:/database/users/'.$id.'/';

SELECT MAX(id) FROM users 

允许您检索最后一个ID,而无需遍历整个用户表。

SELECT id FROM users ORDER BY id DESC LIMIT 1 

答案 1 :(得分:2)

由于Browse filenames within a single folder and look for similarities if two or more files have similar filenames, compare file mod dates determine which file(s) are older delete older file(s) Leave most current file Repeat for all dupes 的值是正确的数组,并且您说它两次获取了该值,因此可以尝试执行此操作,声明$lastrow并尝试将值重新分配给{{1} },然后另一个变量将处理类似$id = array()的值并将其设置为类似$id = array_shift($lastrow)的变量,这应该获取值$implodedArray = implode($id)。这是一种操作数组的想法。