将 underscore.js 代码更改为 php
Change underscore.js codes to php
你能告诉我,如何重写 php 中的这一行吗?没看懂。
var last = .map(.filter(brackets, function(b) {
return b.nextGame == i;
}), function(b) {
return {
game: b.bracketNo,
teams: b.teamnames
};
});
在 underscore.js;
解决方案是(类似于)这个:
$last = array_map(function($b) {
return [
'game' => $b['bracketNo'],
'teams' => $b['teamnames']
];
}, array_filter($brackets, function($b) {
return $b['nextGame'] == $i;
}));
或者,如果您使用对象而不是关联数组:
$last = array_map(function($b) {
return (object) [
'game' => $b->bracketNo,
'teams' => $b->teamnames
];
}, array_filter($brackets, function($b) {
return $b->nextGame == $i;
}));
注意 PHP 的 array_map 中的参数顺序与 UnderscoreJS 的 map 函数不同。
你能告诉我,如何重写 php 中的这一行吗?没看懂。
var last = .map(.filter(brackets, function(b) {
return b.nextGame == i;
}), function(b) {
return {
game: b.bracketNo,
teams: b.teamnames
};
});
在 underscore.js;
解决方案是(类似于)这个:
$last = array_map(function($b) {
return [
'game' => $b['bracketNo'],
'teams' => $b['teamnames']
];
}, array_filter($brackets, function($b) {
return $b['nextGame'] == $i;
}));
或者,如果您使用对象而不是关联数组:
$last = array_map(function($b) {
return (object) [
'game' => $b->bracketNo,
'teams' => $b->teamnames
];
}, array_filter($brackets, function($b) {
return $b->nextGame == $i;
}));
注意 PHP 的 array_map 中的参数顺序与 UnderscoreJS 的 map 函数不同。