考虑 Javascript 中的以下数组:
var array1 = ['S', 'T', 'A', 'C', 'K', 'O', 'V', 'E', 'R', 'F', 'L', 'O', 'W'];
Run Code Online (Sandbox Code Playgroud)
现在我想通过以下方式一次性替换从索引 3 到 9 的所有元素:
array1 = ['S', 'T', 'A', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'L', 'O', 'W'];
Run Code Online (Sandbox Code Playgroud)
可以用javascript实现吗?
注意:我想仅使用数组执行以下操作
我正在使用 laravel 6 并使用 eloquent join 来显示来自多个表的数据。
考虑以下代码:
$ToGetDefaultAddress
= TbPersonaddress::join('tb_cities AS TbCitie','TbCitie.n_CityId_PK', '=', 'tb_personaddresses.n_CityId_FK')
->join('tb_counties AS TbCountie','TbCountie.n_CountyId_PK', '=', 'tb_personaddresses.n_CountyId_FK')
->join('tb_states AS TbState', 'TbState.n_StateId_PK','=' ,'tb_personaddresses.n_StateId_FK')
->select('tb_personaddresses.n_PersonAddressesId_PK','tb_personaddresses.n_PersonId_FK',
'tb_personaddresses.d_EffectiveDateFrom','tb_personaddresses.d_EffectiveDateTo',
'TbCitie.s_CityCode','TbCitie.s_CityName','TbCountie.s_CountyCode',
'TbCountie.s_CountyName','TbState.s_StateCode','TbState.s_StateName')->first();
dd("Actual output:::::",$ToGetDefaultAddress);
Run Code Online (Sandbox Code Playgroud)
如上面的代码所示,我将此输出存储在$ToGetDefaultAddress变量中。现在只得到了属性数据,都toArray()和getAttributes()回报我同样的结果。
例如:
$DefaultAddress = $ToGetDefaultAddress->toArray();
Run Code Online (Sandbox Code Playgroud)
和
$DefaultAddress = $ToGetDefaultAddress->getAttributes();
Run Code Online (Sandbox Code Playgroud)
我的问题是, usingtoArray()和 有getAttributes()什么区别?推荐哪一款?何时使用toArray(),何时使用getAttributes()?
我正在使用 PHP 代码将多个 CSV 文件中的数据上传到数据库中。
每当我从 CSV 文件插入记录时,我都想为无法插入数据库的记录维护一个单独的日志。例如,在上面的 CSV 文件中,如果记录 2,3 和 4 被插入到数据库中,但由于某些原因没有插入 5,我想为此保留一个单独的日志。我怎样才能做到这一点?
这是我的示例 CSV 文件数据:
这是我的php代码:
$csvFile= fopen($dir.'/'.$file,"r");
while (($line = fgetcsv($csvFile)) !== FALSE) {
// Get row data
$account_code = $line[0];
$caller_number = $line[1];
$callee_number = $line[2];
$context = $line[3];
$calerid = $line[4];
$source_channel=$line[5];
$dest_channel=$line[6];
$lastapp=$line[7];
$lastdata=$line[8];
$start_time=$line[9];
$answer_time=$line[10];
$end_time=$line[11];
$query = $db->query
("INSERT INTO `cdrnew`(`account_code`, `caller_number`, `callee_number`, `context`, `calerid`, `source_channel`, `dest_channel`, `lastapp`, `lastdata`, `start_time`, `answer_time`, `end_time`)
VALUES ('".$account_code."', '".$caller_number."', '".$callee_number."', '".$context."', '".$calerid."','".$source_channel."','".$dest_channel."','".$lastapp."','".$lastdata."','".$start_time."','".$answer_time."','".$end_time."')");
}
fclose($csvFile);
Run Code Online (Sandbox Code Playgroud)