我在JavaScript中有一个已定义这些值的数组:
var myStringArray = ["1","2","3","4","5","6","7","8","9","10"];
Run Code Online (Sandbox Code Playgroud)
当我第一次调用函数函数时,我需要得到这个:
1
2
3
Run Code Online (Sandbox Code Playgroud)
再次打电话给我需要:
4
5
6
Run Code Online (Sandbox Code Playgroud)
再次打电话:
7
8
9
Run Code Online (Sandbox Code Playgroud)
再次打电话:
10
1
2
Run Code Online (Sandbox Code Playgroud)
再次打电话:
3
4
5
Run Code Online (Sandbox Code Playgroud)
等等.你得到了重点,显示了数组中的3个值,如果我们在数组的末尾,请从头开始阅读......我有一个具有远程控制功能的应用程序,并且具有向下和向上键.当用户按下向下按钮从数组中获取这些值时,如上例所示,如果用户按下向上按钮,则需要从示例返回...所以在循环中读取数组(最后,数组从头开始读取,但始终显示三个值).
我尝试使用这个:
var myStringArray = ["1","2","3","4","5","6","7","8","9","10"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
if (i<(6)) {
console.log(myStringArray[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
但是下次我调用这段代码时,它会从数组的开头显示,而不是继续读取其他值...我需要第二个计数器吗?
我有以下 JSON 格式:
{
"S01": ["001.cbf", "002.cbf", "003.cbf", "004.cbf", "005.cbf", "006.cbf", "007.cbf", "008.cbf", "009.cbf"],
"S02": ["001.sda", "002.sda", "003.sda"],
"S03": ["001.klm", "002.klm"]
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用此代码:
$json = json_decode('{"S01":["001.cbf","002.cbf","003.cbf","004.cbf","005.cbf","006.cbf","007.cbf","008.cbf","009.cbf"],"S02":["001.sda","002.sda","003.sda"],"S03":["001.klm","002.klm"]}');
foreach($json as $key => $val) {
if ($key) { echo 'KEY IS: '.$key; };
if ($val) { echo 'VALUE IS: '.$value; };
echo '<br>';
}
Run Code Online (Sandbox Code Playgroud)
但我得到了空的结果......我需要得到这样的输出:
KEY IS: S01
VALUE IS: 001.cbf
VALUE IS: 002.cbf
VALUE IS: 003.cbf
VALUE IS: 004.cbf
VALUE IS: 005.cbf
VALUE IS: 006.cbf
VALUE IS: 007.cbf
VALUE IS: 008.cbf
VALUE …Run Code Online (Sandbox Code Playgroud) 我需要检查字符串是否包含两个或更多特定单词,如果发现回声单词..我尝试使用此..但如果找到一个单词然后它回显发现它现在有效:
试试代码:
if(preg_match("/(s|g898|w63)/i", $string)){
echo 'found';
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试使用这个例子:
$string = 'Today is wonderfull day w63';
Run Code Online (Sandbox Code Playgroud)
以上功能无需任何操作.
$string = 'Above the sky limit s g898 w63';
Run Code Online (Sandbox Code Playgroud)
这个字符串需要从上面的函数回显echo 'found'.
那么如何在PHP中检查字符串是否包含所有三个特定单词并且是否包含所有三个echo?
我在 mysql 中有这样的 JSON 格式,很好:
{"2017": {"1": {"payed": 0, "charge": 0}}}
Run Code Online (Sandbox Code Playgroud)
现在我需要再添加一年,JSON 现在看起来像这样:
{"2017": {"1": {"payed": 0, "charge": 0}}, "2018": {"1": {"payed": 0, "charge": 0}}}
Run Code Online (Sandbox Code Playgroud)
我尝试使用这个 MySQL 代码:
UPDATE calculation
SET payment = JSON_ARRAY_APPEND(payment, '$', '{"2018": {"1": {"payed": 0,"charge": 0}}}');
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
[{"2017": {"1": {"payed": 0, "charge": 0}}}, "{\"2018\": {\"1\": {\"payed\": 0,\"charge\": 0}}}"]
Run Code Online (Sandbox Code Playgroud)
所以你看到我有反斜杠 \ 并且需要删除它,并且在开头和结尾也是不必要的 " 那么如何删除它以获得所需的效果,看起来完全像这样:
{"2017": {"1": {"payed": 0, "charge": 0}}, "2018": {"1": {"payed": 0, "charge": 0}}}
Run Code Online (Sandbox Code Playgroud)