我有一个谷歌表单,从其中收集的数据存储在电子表格中,然后我使用PHP通过google API从电子表格中获取数据。Link Of the Spreadsheet,这是代码
<?php
$t=time();
echo($t . "<br>");
echo(date("Y-m-d",$t));
require __DIR__ . '/vendor/autoload.php';
$client = new \Google_Client();
$client->setApplicationName('Google Sheets and PHP');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('Offline');
$client->setAuthConfig(__DIR__ . '/credentials.json');
$service = new Google_Service_Sheets($client);
$spreadsheetId = "10Ta70Faby4FnbZ_bhELRRPNJ4W8m6rrhdPj5lX0ijZ8";
$range = "sfi!A2:D31";
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
if(empty($values)) {
print "You suck";
}
foreach($values as $row) {
$mask = "%s\n%s\n%s\n";
$mask2 = "%s\n";
$values2 = sprintf($mask,$row[1], $row[2],$row[3]);
$values3 = sprintf($mask2, $row[3]);
print($values2);
$fp = fopen($t + '.csv', 'a');//opens file in append mode
fwrite($fp, $values2);
fclose($fp);
}
?>
我想知道当2个或更多的用户在row3中有相同的兴趣,即相同的数据时,我应该怎么做?我试过使用similar_text,但它不起作用。任何帮助都将不胜感激!
发布于 2021-07-27 02:28:42
你为什么要试着比较数据?如果只是想在您的任何用户之间存在共享兴趣时得到通知,您可以决定使用一个数组来存储每个兴趣,并通过使用array_count_values($array)
函数计算该数组的重复项。一个示例,从this answer复制
$interestsArray = [12,43,66,21,56,43,43,78,78,100,43,43,43,21];
$vals = array_count_values($interestsArray);
echo 'No. of NON Duplicate Items: '.count($vals).'<br><br>';
print_r($vals);
结果:
No. of NON Duplicate Items: 7
Array
(
[12] => 1
[43] => 6
[66] => 1
[21] => 2
[56] => 1
[78] => 2
[100] => 1
)
https://stackoverflow.com/questions/68534571
复制相似问题