我有数据由“,”分隔的平面文件,我需要将值与 url 进行比较,并仅显示具有相同 url 值的值
不需要 PHP 的 CSV 函数,如果与来自 url 的值最终比较时,我想比较并得到结果
csv 有 4 个值,价格、大小、宽度和高度
URL 值发送其他值,但顺序相同(价格、大小、宽度和高度),例如在 url 中我使用字符串 index.php?price=100&size=100&width=200&height=300 发送这个..... 。 , ETC
例如 :
<?php
$csv_file=file("test.csv");
for($i=0;$i<sizeof($csv_file);$i++) {
$exp_csv=explode(",",$csv_file[$i]);
foreach($exp_csv as $exp_csv2) {
$csv_end_values[]=$exp_csv2
}
}
/// By Other side the url
$exp_url="100,30,400,500";
$exp_url_values=explode(",",$exp_url);
foreach($exp_url_values as $exp_url_values2) {
$url_end_values[]=$exp_url_values2;
}
/// Finally we have 2 arrays one array with all values we
get in bucle for csv and by other side values get from url ,
now we need compare url values with values of csv ,
for example if in the url we have only 2 values and no 4 show
only results with the same of 2 values from url and compare
in the same order , if when compare the values no the same all , get 0 results
/// For example values from URL 100,,200,,
if in csv exists one row with the values 100 and 200
in the same order show as result and if no , no show
/// In this point i try use array_difference ,
but no works , because i need compare all values i send by
url and in the same order
$aa = array_diff($url_end_values,csv_end_values);
$num_results=0;
foreach($aa as $bb) {
$num_results++;
}
if ($num_results==0) {
print "We get Results";
}
else {
print "No Results";
}
?>