我试图\n在我的foreach声明中添加一个换行符.
我的代码:
$ga->requestReportData($profileId,array('country'),array('visits'));
$array = array();
foreach($ga->getResults() as $result){
$array[] = "['".$result->getcountry()."', ".$result->getVisits()."]";
}
echo implode(",\n", $array);
Run Code Online (Sandbox Code Playgroud)
我的结果之间只有逗号和空格.我想要一个逗号和换行符.
我想要得到这样的东西:
['国家','数字'],
['国家','数字'],
['国家','号码']
但是我得到这个:
['Country','number'],['Country','number'],['Country','number']
为什么我的\n不会引起换行?
A)我有第一个功能很好用:
if(onlyUs == '1' && idUser == '0'){
obj.after(jQuery('<div />').css({'clear':'both'}).addClass('kklike-msg').text('Only registered users can vote.'));
setTimeout(function(){
jQuery('.kklike-msg').fadeOut('normal');
},3000);
return false;
}
Run Code Online (Sandbox Code Playgroud)
B)所以我想我可以做以下事情:
if(idUser == '0'){
if(action == 'like'){
var ajaxAction = 'add_like';
}else{
var ajaxAction = 'remove_like';
}
}else{
if(action == 'like'){
var ajaxAction = 'add_like';
window.open('http://mywebsite.com/like')
}else{
var ajaxAction = 'remove_like';
window.open('http://mywebsite.com/remove')
}
}
Run Code Online (Sandbox Code Playgroud)
C) 知道原始函数很简单(运行良好):
if(action == 'like'){
var ajaxAction = 'add_like';
}else{
var ajaxAction = 'remove_like';
}
Run Code Online (Sandbox Code Playgroud)
但是 B) 不起作用。在两种情况下(登录与否),新窗口都会打开。你有解决方案吗 ?
我想动态更改导航栏中的特定参数。我有这个网址,想将“pedro”更改为“max”:
http://mywebsite.com/?par1=mynameis&par2=pedro&par3=nicetomeetyou
通过使用它,它删除了我的所有参数。
hello = "max"
window.history.replaceState(null, null, "?par2="+hello);
Run Code Online (Sandbox Code Playgroud)
这就是我要的:
http://mywebsite.com/?par1=mynameis&par2=max&par3=nicetomeetyou
Run Code Online (Sandbox Code Playgroud)
并不是
http://mywebsite.com/?par1=mynameis&par2=max
Run Code Online (Sandbox Code Playgroud)