//比如 id 对应的值为以下数组
$info = array(1=>'张三',2=>'李四',3=>'王五');
$ids = implode(',',array_keys($info)) //获取所有的ID字符串
//组合sql
$sql = "UPDATA user SET username = CASE id";
foreach($info as $id=>$username){
$sql .= sprintf("WHEN %d THEN %s",$id,$username);
}
$sql .= "END WHERE id IN ($ids)";
// $model->query($sql)
int main() {
int num = 10;
float pi = 3.14159;
char letter = 'A';
char name[] = "John";
printf("The number is %d\n", num);
printf("The value of pi is %.2f\n", pi);
printf("The letter is %c\n", letter);
printf("The name is %s\n", name);
return 0;
}
登录后复制
运行以上代码,将会输出以下结果:
The number is 10
The value of pi is 3.14
The letter is A
The name is John
<?php<br>$n = 43951789; $u = -43951789; $c = 65; // ASCII 65 is ''A'' // notice the double %%, this prints a literal ''%'' character printf("%%b = ''%b''\n", $n); // binary representation printf("%%c = ''%c''\n", $c); // print the ascii character, same as chr() function printf("%%d = ''%d''\n", $n); // standard integer representation printf("%%e = ''%e''\n", $n); // scientific notation printf("%%u = ''%u''\n", $n); // unsigned integer representation of a positive integer printf("%%u = ''%u''\n", $u); // unsigned integer representation of a negative integer printf("%%f = ''%f''\n", $n); // floating point representation printf("%%o = ''%o''\n", $n); // octal representation printf("%%s = ''%s''\n", $n); // string representation printf("%%x = ''%x''\n", $n); // hexadecimal representation (lower-case) printf("%%X = ''%X''\n", $n); // hexadecimal representation (upper-case)
printf("%%+d = ''%+d''\n", $n); // sign specifier on a positive integer printf("%%+d = ''%+d''\n", $u); // sign specifier on a negative integer
The printout of this program would be: %b = ''10100111101010011010101101'' %c = ''A'' %d = ''43951789'' %e = ''4.39518e+7'' %u = ''43951789'' %u = ''4251015507'' %f = ''43951789.000000'' %o = ''247523255'' %s = ''43951789'' %x = ''29ea6ad'' %X = ''29EA6AD'' %+d = ''+43951789'' %+d = ''-43951789''
例2: string specifiers
<?php $s = ''monkey''; $t = ''many monkeys'';
printf("[%s]\n", $s); // standard string output printf("[%10s]\n", $s); // right-justification with spaces printf("[%-10s]\n", $s); // left-justification with spaces printf("[%010s]\n", $s); // zero-padding works on strings too printf("[%''#10s]\n", $s); // use the custom padding character ''#'' printf("[%10.10s]\n", $t); // left-justification but with a cutoff of 10 characters
The printout of this program would be: [monkey] [ monkey] [monkey ] [0000monkey] [####monkey] [many monke]
// notice the double %%, this prints a literal ''%'' character printf("%%b = ''%b''/n", $n); // binary representation printf("%%c = ''%c''/n", $c); // print the ascii character, same as chr() function printf("%%d = ''%d''/n", $n); // standard integer representation printf("%%e = ''%e''/n", $n); // scientific notation printf("%%u = ''%u''/n", $n); // unsigned integer representation of a positive integer printf("%%u = ''%u''/n", $u); // unsigned integer representation of a negative integer printf("%%f = ''%f''/n", $n); // floating point representation printf("%%o = ''%o''/n", $n); // octal representation printf("%%s = ''%s''/n", $n); // string representation printf("%%x = ''%x''/n", $n); // hexadecimal representation (lower-case) printf("%%X = ''%X''/n", $n); // hexadecimal representation (upper-case)
printf("%%+d = ''%+d''/n", $n); // sign specifier on a positive integer printf("%%+d = ''%+d''/n", $u); // sign specifier on a negative integer ?>
The printout of this program would be: %b = ''10100111101010011010101101'' %c = ''A'' %d = ''43951789'' %e = ''4.39518e+7'' %u = ''43951789'' %u = ''4251015507'' %f = ''43951789.000000'' %o = ''247523255'' %s = ''43951789'' %x = ''29ea6ad'' %X = ''29EA6AD'' %+d = ''+43951789'' %+d = ''-43951789''
例2: string specifiers
复制代码 代码如下:
立即学习“PHP免费学习笔记(深入)”;
点击下载“修复打印机驱动工具”;
$s = ''monkey''; $t = ''many monkeys'';
printf("[%s]/n", $s); // standard string output printf("[%10s]/n", $s); // right-justification with spaces printf("[%-10s]/n", $s); // left-justification with spaces printf("[%010s]/n", $s); // zero-padding works on strings too printf("[%''#10s]/n", $s); // use the custom padding character ''#'' printf("[%10.10s]/n", $t); // left-justification but with a cutoff of 10 characters ?>
The printout of this program would be: [monkey] [ monkey] [monkey ] [0000monkey] [####monkey] [many monke]