嗨,我正在尝试检查2d数组中的三个值是否相同。
我想使用以下语句来做到这一点:board[0][i] == board[1][i] == board[2][i]
。
不幸的是,这给了我 false 作为答案,但是以下语句得出的结果为true:board[0][i] == board[1][i] && board[0][i] == board[2][i]
我不知道为什么,有什么主意吗?
答案 0 :(得分:4)
Python支持该表示法,但不支持javascript。因此,此操作首先评估第一个比较,然后将header('Access-Control-Expose-Headers: filename');
$JSON = file_get_contents('php://input');
$data = json_decode($JSON, TRUE);
//use your json data to find the file your looking for
$file = FULL_PATH_TO_FILE;
$size = filesize($file);
header ( 'Content-Description: File Transfer' );
header("Content-Type: application/force-download");
header ( 'Content-Type: application/octet-stream' );
header ( 'Content-Disposition: attachment; filename=' . str_replace("_", " ", basename ($file)));
header ( 'Expires: 0' );
header ( 'Cache-Control: must-revalidate' );
header ( 'Pragma: public' );
header ( 'Content-Length: ' . filesize ( $file ) );
ob_clean();
flush();
readfile ( $file );
exit();
结果与board [2] [i]元素进行比较,这是错误的。
即这与var data = {
ID: 1,
FileName: “example_file_name.pdf”
}
var req = new XMLHttpRequest();
req.open("POST", `https://api.server.com/download.php`, true);
req.responseType = "blob";
req.onload = (event) => {
var blob = req.response;
var filename = "";
var disposition = req.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1]) {
filename = matches[1].replace(/['"]/g, '');
}
}
const href = window.URL.createObjectURL(blob);
var a = document.createElement("a");
a.download = filename;
a.href = href;
a.click();
};
req.send(JSON.stringify(data));
相同,后者与给定值的相等性没有明确的关系。考虑以下三个明显不同的值:
true
还要注意,(a == b) == c
和a = 'x'
b = 'y'
c = false
console.log(a == b == c)
是evil and should never be used。改用==
和!=
。