我有一个对象.它看起来如下:
[
{
"name":"Display",
"group":"Technical detals",
"id":"60",
"value":"4"
},
{
"name":"Manufacturer",
"group":"Manufacturer",
"id":"58",
"value":"Apple"
},
{
"name":"OS",
"group":"Technical detals",
"id":"37",
"value":"Apple iOS"
}
]
Run Code Online (Sandbox Code Playgroud)
我想按组字段对这些数据进行分组并获取此对象:
var obj = {
0 = [
{
'group' = 'Technical detals',
'name' = 'Display',
'id' = '60',
'value' = '4'
},
{
'group' = 'Technical detals',
'name' = 'OS',
'id' = '37',
'value' = 'Apple iOS'
}],
1 = [
{
'group' = 'Manufacturer',
'name' = 'Manufacturer',
'id' = '58',
'value' = 'Apple'
}] …Run Code Online (Sandbox Code Playgroud) 也许你会帮助我查询我的SQL.我的问题是基于另一个问题:Mysql | 分面搜索 一切都是一样的,我需要相同的结果,但表格略有不同.我无法构建我的查询.请看看这个sql小提琴:
我的表结构:
CREATE TABLE products
(`id` int, `description` varchar(9), `user_id` int);
INSERT INTO products
(`id`, `description`, `user_id`)
VALUES
(1, 'my car', 3),
(2, 'dream car', 3),
(3, 'New car', 3),
(4, 'Old car', 4);
CREATE TABLE fields
(`id` int, `field_name` varchar(14)); /*meta_name*/
INSERT INTO fields
(`id`, `field_name`)
VALUES
(1, 'Make'),
(2, 'Model'),
(3, 'Color'),
(4, 'Car Type'),
(5, 'Interior Color');
CREATE TABLE fields_values
(`id` int, `field_id` int, `field_value` varchar(7)); /*meta_value*/
INSERT INTO fields_values
(`id`, …Run Code Online (Sandbox Code Playgroud) 我有一张桌子,想找到最低和最高价格.我希望在"from"和"to"之间的当前日期从action_table获得最低价格.
from to action_price price
2015-04-02 2015-08-02 20 25
2015-04-02 2015-04-20 0 30
2015-04-03 2015-04-21 0 40
Run Code Online (Sandbox Code Playgroud)
所以从上表我需要:min-> 20(因为"from"/"to"之间的当前日期)和max-> 40
我尝试了类似的东西,但没有按预期工作:
SELECT
CASE WHEN curdate() BETWEEN from AND to THEN MAX(action_price) ELSE MAX(price) END AS max,
CASE WHEN curdate() BETWEEN from AND to THEN MIN(action_price) ELSE MIN(price) END AS min
FROM `table`;
Run Code Online (Sandbox Code Playgroud) 我正在寻找解决方案来删除<li>使用javascript数组过滤的标签.
阵:
var mygroups=["1","8","3","4","5"]
Run Code Online (Sandbox Code Playgroud)
示例(输入):
<li><div>1 element.</div></li>
<li><div>2 element. This is my <span>post</span> into new group</div></li>
<li><div>3 element. Another one</li>
<li><div>
<a href="javascript:void(0);">Actor</a>
<a href="/groups/viewgroup/1-first-group">First group</a>
</div>
</li>
<li><div><a href="javascript:void(0);">Actor</a>
<a href="/groups/viewgroup/10-ten-group">Ten group</a>5 element. This is my <span>new post</span></div></li>
<li>
<div>6 element. <a href="/j1.5/index.php/jomsocial/63-zzz/profile">Actor</a></div>
<div><a href="/groups/viewgroup/test/5-second-group">Group other</a></div>
</li>
<li>7 element.</li>
<li><div><a href="/groups/viewgroup/test/8-second-group">First group</a></div></li>
<li><div><a href="/groups/viewgroup/16-other-group">First group</a></div></li>
<li><div><a href="/j1.5/index.php?option=com_community&view=groups&task=viewgroup&groupid=1&Itemid=4">My other group </a></div></li>
Run Code Online (Sandbox Code Playgroud)
如何获取此输出(删除锚点中不包含数组中的组的所有实例):
<li><div>
<a href="javascript:void(0);">Actor</a>
<a href="/groups/viewgroup/1-first-group">First group</a>
</div>
</li>
<li>
<div>6 element. <a href="/j1.5/index.php/jomsocial/63-zzz/profile">Actor</a></div>
<div><a href="/groups/viewgroup/test/5-second-group">Group other</a></div> …Run Code Online (Sandbox Code Playgroud) 如何从我的数组中获取值列表:
[data] => Array
(
[5] => Array
(
[0] => 19
[1] => 18
[2] => 20
)
[6] => Array
(
[0] => 28
)
)
Run Code Online (Sandbox Code Playgroud)
预期的输出结果字符串将是:19,18,20,28
谢谢!
也许你可以帮助我:我的javascript代码:
bbchatdecode: function(text) {
var chars = Array(":\\)","8-\\)",":cry:",":oops:");
var replacements = Array('<img src=\"smiley-smile.gif\" alt=\":)\">','<img src=\"smiley-cool.gif\" alt=\"8-)\">','<img src=\"smiley-cry.gif\" alt=\":cry:\">','<img src=\"smiley-embarassed.gif\" alt=\"oops:\">');
for (var ic=0; ic<chars.length; ic++) {
var re = new RegExp(chars[ic], "gi");
if(re.test(text))
{
text = text.replace(re, replacements[ic]);
}
}
return text;
}
Run Code Online (Sandbox Code Playgroud)
但在浏览器中我可以看到:
)正则表达式无与伦比
如何将PHP中的MYSQL TIMEZONE更改为GMT格式:/ SET GMT TIMEZONE/date_default_timezone_set('Etc/GMT');
我的DB类在这里:
class DB {
private static $instance;
private $MySQLi;
private function __construct(array $dbOptions){
$this->MySQLi = @ new mysqli( $dbOptions['db_host'],
$dbOptions['db_user'],
$dbOptions['db_pass'],
$dbOptions['db_name'] );
if (mysqli_connect_errno()) {
throw new Exception('Database error.');
}
$this->MySQLi->set_charset("utf8");
}
public static function init(array $dbOptions){
if(self::$instance instanceof self){
return false;
}
self::$instance = new self($dbOptions);
}
public static function getMySQLiObject(){
return self::$instance->MySQLi;
}
public static function query($q){
return self::$instance->MySQLi->query($q);
}
public static function prepare($q){
return self::$instance->MySQLi->prepare($q);
}
public static function esc($str){ …Run Code Online (Sandbox Code Playgroud) 我有一个元素数组:
$arr = array(
'0' => 265000, // Area
'1' => 190000,
'2' => 30000,
'3' => 1300
);
Run Code Online (Sandbox Code Playgroud)
我想根据区域(数组值)获取随机索引。我需要更频繁地选择具有大价值的区域。我怎样才能做到这一点?
我现在拥有的:
$random_idx = mt_rand(0, count($arr)-1);
$selected_area = (object)$arr[$random_idx];
Run Code Online (Sandbox Code Playgroud)
谢谢!
我有一个 EBNF 语法,想将其转换为 PEG ( https://github.com/anatoo/PHPPEG ):
\n\nquery = { word | wildcard }\nword = ( [apostrophe] ( letter { alpha } ) ) | \xe2\x80\x9d , \xe2\x80\x9d\nletter = \xe2\x80\x9d a \xe2\x80\x9d | ... | \xe2\x80\x9d z \xe2\x80\x9d | \xe2\x80\x9d A \xe2\x80\x9d | ... | \xe2\x80\x9d Z \xe2\x80\x9d\nalpha = letter | \xe2\x80\x9d 0 \xe2\x80\x9d | ... | \xe2\x80\x9d 9 \xe2\x80\x9d\napostrophe = \xe2\x80\x9d \xe2\x80\x99 \xe2\x80\x9d\nwildcard = \xe2\x80\x9d ? \xe2\x80\x9d | \xe2\x80\x9d * \xe2\x80\x9d | synonyms | multiset | optionset\nsynonyms = …Run Code Online (Sandbox Code Playgroud) 我有一个array_diff函数数组,如下所示:
Array
(
[0] => world
[1] => is
[2] => a
[3] => wonderfull
[5] => in
[6] => our
)
Run Code Online (Sandbox Code Playgroud)
如您所见,我们在键#3和#5之间存在间隙(即没有键#4).如何将该阵列分成两部分,如果有更多间隙,可能会更多?预期的产出是:
Array
(
[0] => Array
(
[0] => world
[1] => is
[2] => a
[3] => wonderfull
)
[1] => Array
(
[0] => in
[1] => our
)
)
Run Code Online (Sandbox Code Playgroud)