jQuery in Novice 群号:9079204 PHP in Practice 群号:24810647
简单的笔记一下
select id,tags,(if(locate('人类',tags),2,0)+if(locate('暴力',tags),2,0)+if(locate('美学',tags),2,0)+if(locate('生物学',tags),2,0)+if(locate('机关枪',tags),2,0)) as zh from details order by zh desc
Generic Reset CSS
Esse com certeza é o mais conhecido e utilizado pelos desenvolvedores:
* {
padding: 0;
margin: 0;
border: 0;
}
Ateneu Popular CSS Reset
CSS inicial sugerido pelo site Ateneu Popular:
html, body, div, span, applet, object, iframe, h1, h2, h3,
h4, h5, h6, p, blockquote, pre, a, abbr, acronym,
address, big, cite, code, del, dfn, em, font, img, ins,
kbd, q, s, samp, small, strike, strong, sub, sup, tt,
var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
:focus { outline: 0;}
a, a:link, a:visited, a:hover, a:active{text-decoration:none}
table { border-collapse: separate;border-spacing: 0;}
th, td {text-align: left; font-weight: normal;}
img, iframe {border: none; text-decoration:none;}
ol, ul {list-style: none;}
input, textarea, select, button {font-size: 100%;font-family: inherit;}
select {margin: inherit;}
hr {margin: 0;padding: 0;border: 0;color: #000;background-color: #000;height: 1px}
Chris Poteet's Reset CSS
Técnica sugerida por Chris Poteet's para Reset CSS:
* {
vertical-align: baseline;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: none;
padding: 0;
margin: 0;
}
body {
padding: 5px;
}
h1, h2, h3, h4, h5, h6, p, pre, blockquote, form, ul, ol, dl {
margin: 20px 0;
}
li, dd, blockquote {
margin-left: 40px;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
Yahoo's CSS Reset
Técnica de Reset CSS proposta pelo Yahoo:
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,
form,fieldset,input,textarea,p,blockquote,th,td {
padding: 0;
margin: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset,img {
border: 0;
}
address,caption,cite,code,dfn,em,strong,th,var {
font-weight: normal;
font-style: normal;
}
ol,ul {
list-style: none;
}
caption,th {
text-align: left;
}
h1,h2,h3,h4,h5,h6 {
font-weight: normal;
font-size: 100%;
}
q:before,q:after {
content:'';
}
abbr,acronym { border: 0;
}
Eric Meyer Reset CSS
Esse com certeza deve ser o mais utilizado entre os desenvolvedores, proposto por Eric Meyer, é o que eu utilizo atualmente:
html, body, div, span, applet, object, iframe, table, caption,
tbody, tfoot, thead, tr, th, td, del, dfn, em, font, img, ins,
kbd, q, s, samp, small, strike, strong, sub, sup, tt, var,
h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr,
acronym, address, big, cite, code, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend {
vertical-align: baseline;
font-family: inherit;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
outline: 0;
padding: 0;
margin: 0;
border: 0;
}
:focus {
outline: 0;
}
body {
background: white;
line-height: 1;
color: black;
}
ol, ul {
list-style: none;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
font-weight: normal;
text-align: left;
}
blockquote:before, blockquote:after, q:before, q:after {
content: "";
}
blockquote, q {
quotes: "" "";
}
Tantek Celik Reset CSS
Técnica de Reset CSS proposta por Tantek Celik:
:link,:visited { text-decoration:none }
ul,ol { list-style:none }
h1,h2,h3,h4,h5,h6,pre,code { font-size:1em; }
ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,body,html,p,blockquote,fieldset,input
{ margin:0; padding:0 }
a img,:link img,:visited img { border:none }
address { font-style:normal }
Christian Montoya Reset CSS
Técnica sugeria por Christian Montoya:
html, body, form, fieldset {
margin: 0;
padding: 0;
font: 100%/120% Verdana, Arial, Helvetica, sans-serif;
}
h1, h2, h3, h4, h5, h6, p, pre,
blockquote, ul, ol, dl, address {
margin: 1em 0;
padding: 0;
}
li, dd, blockquote {
margin-left: 1em;
}
form label {
cursor: pointer;
}
fieldset {
border: none;
}
input, select, textarea {
font-size: 100%;
font-family: inherit;
}
Rudeworks Reset CSS
Técinca de Reset CSS proposta por Rudeworks:
* {
margin: 0;
padding: 0;
border: none;
}
html {
font: 5% "Lucida Grande", Lucida, Verdana, sans-serif;
text-shadow: #000 0px 0px 0px;
}
ul {
list-style: none;
list-style-type: none;
}
h1, h2, h3, h4, h5, h6, p, pre,
blockquote, ul, ol, dl, address {
font-weight: normal;
margin: 0 0 1em 0;
}
cite, em, dfn {
font-style: italic;
}
sup {
position: relative;
bottom: 3em;
vertical-align: baseline;
}
sub {
position: relative;
bottom: -2em;
vertical-align: baseline;
}
li, dd, blockquote {
margin-left: 1em;
}
code, kbd, samp, pre, tt, var, input[type='text'], textarea {
font-size: 100%;
font-family: monaco, "Lucida Console", courier, mono-space;
}
del {
text-decoration: line-through;
}
ins, dfn {
border-bottom: 1px solid #ccc;
}
small, sup, sub {
font-size: 85%;
}
abbr, acronym {
text-transform: uppercase;
font-size: 85%;
letter-spacing: .1em;
border-bottom-style: dotted;
border-bottom-width: 1px;
}
a abbr, a acronym {
border: none;
}
sup {
vertical-align: super;
}
sub {
vertical-align: sub;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 8em;
}
h3 {
font-size: 6em;
}
h4 {
font-size: 4em;
}
h5 {
font-size: 2em;
}
h6 {
font-size: 1em;
}
a, a:link, a:visited, a:hover, a:active {
outline: 0;
text-decoration: none;
}
a img {
border: none;
text-decoration: none;
}
img {
border: none;
text-decoration: none;
}
label, button {
cursor: pointer;
}
input:focus, select:focus, textarea:focus {
background-color: #FFF;
}
fieldset {
border: none;
}
.clear {
clear: both;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
body {
text-align: center;
}
#wrapper {
margin: 0 auto;
text-align: left;
}
Anieto2K Reset CSS
Técnica de Reset CSS proposta por Andrés Nieto:
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p,
blockquote, pre, a, abbr, acronym, address, big,
cite, code, del, dfn, em, font, img,
ins, kbd, q, s, samp, small, strike,
strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
center, u, b, i {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: normal;
font-style: normal;
font-size: 100%;
font-family: inherit;
vertical-align: baseline
}
body {
line-height: 1
}
:focus {
outline: 0
}
ol, ul {
list-style: none
}
table {
border-collapse: collapse;
border-spacing: 0
}
blockquote:before, blockquote:after, q:before, q:after {
content: ""
}
blockquote, q {
quotes: "" ""
}
input, textarea {
margin: 0;
padding: 0
}
hr {
margin: 0;
padding: 0;
border: 0;
color: #000;
background-color: #000;
height: 1px
}
CSSLab CSS Reset
Técnica de CSS Reset proposta pelo site CSSLab:
html, body, div, span, applet, object, iframe, h1, h2, h3,
h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address,
big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend, table, caption, tbody, tfoot,
thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
:focus {
outline: 0;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
a img, iframe {
border: none;
}
ol, ul {
list-style: none;
}
input, textarea, select, button {
font-size: 100%;
font-family: inherit;
}
select {
margin: inherit;
}
/* Fixes incorrect placement of numbers in ol's in IE6/7 */
ol { margin-left:2em; }
/* == clearfix == */
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {display: inline-block;}
* html .clearfix {height: 1%;}
.clearfix {display: block;}
Esse com certeza é o mais conhecido e utilizado pelos desenvolvedores:
* {
padding: 0;
margin: 0;
border: 0;
}
Ateneu Popular CSS Reset
CSS inicial sugerido pelo site Ateneu Popular:
html, body, div, span, applet, object, iframe, h1, h2, h3,
h4, h5, h6, p, blockquote, pre, a, abbr, acronym,
address, big, cite, code, del, dfn, em, font, img, ins,
kbd, q, s, samp, small, strike, strong, sub, sup, tt,
var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
:focus { outline: 0;}
a, a:link, a:visited, a:hover, a:active{text-decoration:none}
table { border-collapse: separate;border-spacing: 0;}
th, td {text-align: left; font-weight: normal;}
img, iframe {border: none; text-decoration:none;}
ol, ul {list-style: none;}
input, textarea, select, button {font-size: 100%;font-family: inherit;}
select {margin: inherit;}
hr {margin: 0;padding: 0;border: 0;color: #000;background-color: #000;height: 1px}
Chris Poteet's Reset CSS
Técnica sugerida por Chris Poteet's para Reset CSS:
* {
vertical-align: baseline;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: none;
padding: 0;
margin: 0;
}
body {
padding: 5px;
}
h1, h2, h3, h4, h5, h6, p, pre, blockquote, form, ul, ol, dl {
margin: 20px 0;
}
li, dd, blockquote {
margin-left: 40px;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
Yahoo's CSS Reset
Técnica de Reset CSS proposta pelo Yahoo:
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,
form,fieldset,input,textarea,p,blockquote,th,td {
padding: 0;
margin: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset,img {
border: 0;
}
address,caption,cite,code,dfn,em,strong,th,var {
font-weight: normal;
font-style: normal;
}
ol,ul {
list-style: none;
}
caption,th {
text-align: left;
}
h1,h2,h3,h4,h5,h6 {
font-weight: normal;
font-size: 100%;
}
q:before,q:after {
content:'';
}
abbr,acronym { border: 0;
}
Eric Meyer Reset CSS
Esse com certeza deve ser o mais utilizado entre os desenvolvedores, proposto por Eric Meyer, é o que eu utilizo atualmente:
html, body, div, span, applet, object, iframe, table, caption,
tbody, tfoot, thead, tr, th, td, del, dfn, em, font, img, ins,
kbd, q, s, samp, small, strike, strong, sub, sup, tt, var,
h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr,
acronym, address, big, cite, code, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend {
vertical-align: baseline;
font-family: inherit;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
outline: 0;
padding: 0;
margin: 0;
border: 0;
}
:focus {
outline: 0;
}
body {
background: white;
line-height: 1;
color: black;
}
ol, ul {
list-style: none;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
font-weight: normal;
text-align: left;
}
blockquote:before, blockquote:after, q:before, q:after {
content: "";
}
blockquote, q {
quotes: "" "";
}
Tantek Celik Reset CSS
Técnica de Reset CSS proposta por Tantek Celik:
:link,:visited { text-decoration:none }
ul,ol { list-style:none }
h1,h2,h3,h4,h5,h6,pre,code { font-size:1em; }
ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,body,html,p,blockquote,fieldset,input
{ margin:0; padding:0 }
a img,:link img,:visited img { border:none }
address { font-style:normal }
Christian Montoya Reset CSS
Técnica sugeria por Christian Montoya:
html, body, form, fieldset {
margin: 0;
padding: 0;
font: 100%/120% Verdana, Arial, Helvetica, sans-serif;
}
h1, h2, h3, h4, h5, h6, p, pre,
blockquote, ul, ol, dl, address {
margin: 1em 0;
padding: 0;
}
li, dd, blockquote {
margin-left: 1em;
}
form label {
cursor: pointer;
}
fieldset {
border: none;
}
input, select, textarea {
font-size: 100%;
font-family: inherit;
}
Rudeworks Reset CSS
Técinca de Reset CSS proposta por Rudeworks:
* {
margin: 0;
padding: 0;
border: none;
}
html {
font: 5% "Lucida Grande", Lucida, Verdana, sans-serif;
text-shadow: #000 0px 0px 0px;
}
ul {
list-style: none;
list-style-type: none;
}
h1, h2, h3, h4, h5, h6, p, pre,
blockquote, ul, ol, dl, address {
font-weight: normal;
margin: 0 0 1em 0;
}
cite, em, dfn {
font-style: italic;
}
sup {
position: relative;
bottom: 3em;
vertical-align: baseline;
}
sub {
position: relative;
bottom: -2em;
vertical-align: baseline;
}
li, dd, blockquote {
margin-left: 1em;
}
code, kbd, samp, pre, tt, var, input[type='text'], textarea {
font-size: 100%;
font-family: monaco, "Lucida Console", courier, mono-space;
}
del {
text-decoration: line-through;
}
ins, dfn {
border-bottom: 1px solid #ccc;
}
small, sup, sub {
font-size: 85%;
}
abbr, acronym {
text-transform: uppercase;
font-size: 85%;
letter-spacing: .1em;
border-bottom-style: dotted;
border-bottom-width: 1px;
}
a abbr, a acronym {
border: none;
}
sup {
vertical-align: super;
}
sub {
vertical-align: sub;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 8em;
}
h3 {
font-size: 6em;
}
h4 {
font-size: 4em;
}
h5 {
font-size: 2em;
}
h6 {
font-size: 1em;
}
a, a:link, a:visited, a:hover, a:active {
outline: 0;
text-decoration: none;
}
a img {
border: none;
text-decoration: none;
}
img {
border: none;
text-decoration: none;
}
label, button {
cursor: pointer;
}
input:focus, select:focus, textarea:focus {
background-color: #FFF;
}
fieldset {
border: none;
}
.clear {
clear: both;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
body {
text-align: center;
}
#wrapper {
margin: 0 auto;
text-align: left;
}
Anieto2K Reset CSS
Técnica de Reset CSS proposta por Andrés Nieto:
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p,
blockquote, pre, a, abbr, acronym, address, big,
cite, code, del, dfn, em, font, img,
ins, kbd, q, s, samp, small, strike,
strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
center, u, b, i {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: normal;
font-style: normal;
font-size: 100%;
font-family: inherit;
vertical-align: baseline
}
body {
line-height: 1
}
:focus {
outline: 0
}
ol, ul {
list-style: none
}
table {
border-collapse: collapse;
border-spacing: 0
}
blockquote:before, blockquote:after, q:before, q:after {
content: ""
}
blockquote, q {
quotes: "" ""
}
input, textarea {
margin: 0;
padding: 0
}
hr {
margin: 0;
padding: 0;
border: 0;
color: #000;
background-color: #000;
height: 1px
}
CSSLab CSS Reset
Técnica de CSS Reset proposta pelo site CSSLab:
html, body, div, span, applet, object, iframe, h1, h2, h3,
h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address,
big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend, table, caption, tbody, tfoot,
thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
:focus {
outline: 0;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
a img, iframe {
border: none;
}
ol, ul {
list-style: none;
}
input, textarea, select, button {
font-size: 100%;
font-family: inherit;
}
select {
margin: inherit;
}
/* Fixes incorrect placement of numbers in ol's in IE6/7 */
ol { margin-left:2em; }
/* == clearfix == */
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {display: inline-block;}
* html .clearfix {height: 1%;}
.clearfix {display: block;}
做前端开发的同学们,也许比较能体会到脚本错误的痛苦,脚本错误产生有很多种原因,从大的方向来分,分为两种,一种是人为的,一种是浏览器加载不全导致。
对于第二种情况,暂时来说是无能为力,至于人为的脚本错误,很多也是不经意所产生的,同样是因为不经意,所以你要找到原因也不容易,在这里给各位同学说说我平时是怎么调试的。
得到的结果是
对于第二种情况,暂时来说是无能为力,至于人为的脚本错误,很多也是不经意所产生的,同样是因为不经意,所以你要找到原因也不容易,在这里给各位同学说说我平时是怎么调试的。
<script>
// 这是一个存在语法错误的JS函数
function test(){
window.location.href = a;
}
// 自定义的调试函数
function debug(message, url, line){
alert(
"Error:" + message +
"\nUrl:" + url +
"\nLine:" + line
);
return false;
}
// 触发脚本错误
window.onload = test;
// 输出调试信息
window.onerror = debug;
</script>
// 这是一个存在语法错误的JS函数
function test(){
window.location.href = a;
}
// 自定义的调试函数
function debug(message, url, line){
alert(
"Error:" + message +
"\nUrl:" + url +
"\nLine:" + line
);
return false;
}
// 触发脚本错误
window.onload = test;
// 输出调试信息
window.onerror = debug;
</script>
得到的结果是
引用
Error:a is not defined
Url:file:///C:/Users/hdj/Desktop/html/jserror.html
Line:13
Url:file:///C:/Users/hdj/Desktop/html/jserror.html
Line:13
引用
官方给出的参考解决方法应该是首选检查的:
1、UCenter 应用 ID 需要和 UCenter 后台的 ID 一致;
2、UCenter 通信密钥需要和 UCenter 后台的通信密钥一致;
3、UCenter 访问地址查看是否是正确的地址;
4、UCenter IP 地址查看是否是 UCenter 所在的 MySQL 服务器的 IP 地址。
1、UCenter 应用 ID 需要和 UCenter 后台的 ID 一致;
2、UCenter 通信密钥需要和 UCenter 后台的通信密钥一致;
3、UCenter 访问地址查看是否是正确的地址;
4、UCenter IP 地址查看是否是 UCenter 所在的 MySQL 服务器的 IP 地址。
一一检查,并没有发现以上所提到的情况,这问题困扰了我相当长的一段时间了,我决定不解决誓不摆休。
后来按照http://www.discuz.net/thread-1388614-1-1.html上面的方法,顺藤摸瓜,找到了真正的原因。
原来是php5.3.x以后对set_magic_quotes_runtime函数默认不支持导致的问题。
//解决办法:找到api/uc.php
第32号:set_magic_quotes_runtime(0);
改为:@set_magic_quotes_runtime(0);
第32号:set_magic_quotes_runtime(0);
改为:@set_magic_quotes_runtime(0);
这个功能需求来自于网站运营策略,举倒子:
在一个排行列表中,默认有以下元素,顺序有一定的依据,假设是按下载次数排列。
$rows = array(
array('name'=>'QQ2010'),
array('name'=>'QQ2009'),
array('name'=>'迅雷5'),
array('name'=>'飞信2010'),
array('name'=>'Kugoo2010'),
array('name'=>'TTplayer'),
array('name'=>'Firefox4.0'),
array('name'=>'美图秀秀'),
array('name'=>'360safe'),
array('name'=>'Chrome6')
);
如果有一个客户[可牛杀毒]想买花10元/元下我们第二个位置,可以大家想,直接把QQ2009替换掉不就完事了吗。不,那样的话用户体验并不好,明明QQ2009是一个下载次数比较多的软件,为什么在列表中却没有了呢。
其实我们真正的需求是把QQ2009以下的单元都往后推,腾出第二个位置来给[可牛杀毒]。如果页面中只能显示10个单元,那倒霉的就是[Chrome6]了,谁叫他们付费买我们的位置呢,呵呵。
再说到程序原理上来吧,PHP要实现这个需求,挺简单,用数组函数array_splice就可以了,具体用法参照PHP手册。
给一个完整的例子吧:
<?php
$rows = array(
array('name'=>'QQ2010',),
array('name'=>'QQ2009',),
array('name'=>'迅雷5',),
array('name'=>'飞信2010',),
array('name'=>'Kugoo2010',),
array('name'=>'TTplayer',),
array('name'=>'Firefox4.0',),
array('name'=>'美图秀秀',),
array('name'=>'360safe',),
array('name'=>'Chrome6',),
);
$pop = array(
'2'=>array('name'=>'可牛杀毒'),
'5'=>array('name'=>'金山词霸2010'),
);
foreach($pop as $key=>$p){
array_splice($rows, $key-1, 0, array($p));
}
var_dump($rows);
?>
最近的结果是:
array(12) {
[0]=>
array(1) {
["name"]=>
string(6) "QQ2010"
}
[1]=>
array(1) {
["name"]=>
string(8) "可牛杀毒"
}
[2]=>
array(1) {
["name"]=>
string(6) "QQ2009"
}
[3]=>
array(1) {
["name"]=>
string(5) "迅雷5"
}
[4]=>
array(1) {
["name"]=>
string(12) "金山词霸2010"
}
[5]=>
array(1) {
["name"]=>
string(8) "飞信2010"
}
[6]=>
array(1) {
["name"]=>
string(9) "Kugoo2010"
}
[7]=>
array(1) {
["name"]=>
string(8) "TTplayer"
}
[8]=>
array(1) {
["name"]=>
string(10) "Firefox4.0"
}
[9]=>
array(1) {
["name"]=>
string(8) "美图秀秀"
}
[10]=>
array(1) {
["name"]=>
string(7) "360safe"
}
[11]=>
array(1) {
["name"]=>
string(7) "Chrome6"
}
}
在一个排行列表中,默认有以下元素,顺序有一定的依据,假设是按下载次数排列。
$rows = array(
array('name'=>'QQ2010'),
array('name'=>'QQ2009'),
array('name'=>'迅雷5'),
array('name'=>'飞信2010'),
array('name'=>'Kugoo2010'),
array('name'=>'TTplayer'),
array('name'=>'Firefox4.0'),
array('name'=>'美图秀秀'),
array('name'=>'360safe'),
array('name'=>'Chrome6')
);
如果有一个客户[可牛杀毒]想买花10元/元下我们第二个位置,可以大家想,直接把QQ2009替换掉不就完事了吗。不,那样的话用户体验并不好,明明QQ2009是一个下载次数比较多的软件,为什么在列表中却没有了呢。
其实我们真正的需求是把QQ2009以下的单元都往后推,腾出第二个位置来给[可牛杀毒]。如果页面中只能显示10个单元,那倒霉的就是[Chrome6]了,谁叫他们付费买我们的位置呢,呵呵。
再说到程序原理上来吧,PHP要实现这个需求,挺简单,用数组函数array_splice就可以了,具体用法参照PHP手册。
给一个完整的例子吧:
<?php
$rows = array(
array('name'=>'QQ2010',),
array('name'=>'QQ2009',),
array('name'=>'迅雷5',),
array('name'=>'飞信2010',),
array('name'=>'Kugoo2010',),
array('name'=>'TTplayer',),
array('name'=>'Firefox4.0',),
array('name'=>'美图秀秀',),
array('name'=>'360safe',),
array('name'=>'Chrome6',),
);
$pop = array(
'2'=>array('name'=>'可牛杀毒'),
'5'=>array('name'=>'金山词霸2010'),
);
foreach($pop as $key=>$p){
array_splice($rows, $key-1, 0, array($p));
}
var_dump($rows);
?>
最近的结果是:
array(12) {
[0]=>
array(1) {
["name"]=>
string(6) "QQ2010"
}
[1]=>
array(1) {
["name"]=>
string(8) "可牛杀毒"
}
[2]=>
array(1) {
["name"]=>
string(6) "QQ2009"
}
[3]=>
array(1) {
["name"]=>
string(5) "迅雷5"
}
[4]=>
array(1) {
["name"]=>
string(12) "金山词霸2010"
}
[5]=>
array(1) {
["name"]=>
string(8) "飞信2010"
}
[6]=>
array(1) {
["name"]=>
string(9) "Kugoo2010"
}
[7]=>
array(1) {
["name"]=>
string(8) "TTplayer"
}
[8]=>
array(1) {
["name"]=>
string(10) "Firefox4.0"
}
[9]=>
array(1) {
["name"]=>
string(8) "美图秀秀"
}
[10]=>
array(1) {
["name"]=>
string(7) "360safe"
}
[11]=>
array(1) {
["name"]=>
string(7) "Chrome6"
}
}





