我有一个名为olmali的数组
$olmali = $_POST['result'];
和
print_r($olmali);
Array (
[0] => 1
[1] => 1
[2] => 20
[3] => 2
[4] => 3
[5] => 5
[6] => 6
[7] => 7
[8] => 9
[9] => 8
[10] => 10
[11] => 11
[12] => 13
[13] => 12
[14] => 12
[15] => 14
[16] => 15
[17] => 16
[18] => 17
[19] => 17
[20] => 19
[21] => 20
)
我想使用SQL UPDATE命令,我期望:
id test
1 1
2 1
3 20
4 2
5 3
6 ....and goes on
如何解决此问题?有什么办法,我该怎么办。 PHP数组使用这样的UPDATE SQL命令到MySQL表中的列行
答案 0 :(得分:0)
假设
public static void main(String[] args) {
String string = "Hello";
// you can call `mapBoo` like normal here
string = mapBoo(string);
System.out.println(string);
List<String> strings = Arrays.asList("Hello", "this", "is", "a", "test");
// or you can pass mapBoo into the stream.map method since map fits the method signature
List<String> mappedStrings = strings.stream().map(Main::mapBoo)
.collect(Collectors.toList());
for (String mappedString : mappedStrings)
System.out.println(mappedString);
}
static String mapBoo(String s) {
return s + "boo";
}
然后使用PDO建立数据库连接后,准备绑定并执行
$myArray = array (
[0] => 1
[1] => 1
[2] => 20
[3] => 2
[4] => 3
[5] => 5
[6] => 6
[7] => 7
[8] => 9
[9] => 8
[10] => 10
[11] => 11
[12] => 13
[13] => 12
[14] => 12
[15] => 14
[16] => 15
[17] => 16
[18] => 17
[19] => 17
[20] => 19
[21] => 20
);
答案 1 :(得分:0)
我建议从C2 = TRIM(RIGHT(A2,LEN(A2)-SEARCH(CHAR(32),TRIM(A2),SEARCH(CHAR(32),TRIM(A2))+1)))
循环开始,并为每个键重新分配值for
。然后,您只需要使用+1
删除数组的第一个索引。请参见下面的代码。
unset()
输出:
$olmali = [
0 => 1,
1 => 1,
2 => 20,
3 => 2,
4 => 3,
5 => 5,
6 => 6,
7 => 7,
8 => 9,
9 => 8,
10 => 10,
11 => 11,
12 => 13,
13 => 12,
14 => 12,
15 => 14,
16 => 15,
17 => 16,
18 => 17,
19 => 17,
20 => 19,
21 => 20
];
for($i = count($olmali); $i > 0; $i--) {
$olmali[$i] = $olmali[$i - 1];
}
unset($olmali[0]);
print_r($olmali);