更新:$ string可以有一个或多个";".我必须照顾最后一个.
$string = "Hello world; This is a nice day; after";
$out[] = trim( substr( strrchr ($string, ";"), 1 ) );
$out[] = trim( substr( strrchr ($string, ";"), 0 ) );
var_dump($out);
Run Code Online (Sandbox Code Playgroud)
结果:array(2){[0] => string(3)"在"[1] => string(5)"后面;"}之后
但我需要的是:
array(2){[0] => string(3)"在"[1] => string(5)之后"Hello world;这是美好的一天"}
我该怎么办?
在PHP中我有一个数组$test.运行var_dump($test)看起来像这样:
array(2) {
[0]=>
object(stdClass)#2 (6) {
["name"]=>
string(45) "Lorem"
["title"]=>
string(96) "Lorem ipsum"
}
[1]=>
object(stdClass)#3 (6) {
["name"]=>
string(41) "Ipsum"
["title"]=>
string(86) "Dolor sit amet"
}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要向对象添加另一个field(url),$test如下所示:
array(2) {
[0]=>
object(stdClass)#2 (6) {
["name"]=>
string(45) "Lorem"
["title"]=>
string(96) "Lorem ipsum"
["url"]=>
string(86) "http://www.google.com"
}
[1]=>
object(stdClass)#3 (6) {
["name"]=>
string(41) "Ipsum"
["title"]=>
string(86) "Dolor sit amet"
["url"]=>
string(86) "http://www.stackoverflow.com"
}
}
Run Code Online (Sandbox Code Playgroud)
我试过foreach()和$test->append('xxxxxxxx');,但我得到的错误.这真的不容易吗?我究竟做错了什么?
<style>
#table{
display:table;
}
#table div.row{
display:table-row;
}
#table div.row div{
display:table-cell;
width:100px;
text-align:right;
}
#table div.row:first-child{
color:white;
background-color:blue;
}
#table div.row:last-child{
color:white;
background-color:green;
}
#table div.row:last-child{
display:none;
}
#table div.row:hover{
display:table-row;
}
</style>
<div id='table'>
<div class='row'>
<div>CELL</div><div>CELL</div><div>CELL</div>
</div>
<div class='row'>
<div>CELL</div><div>CELL</div><div>CELL</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我不能摆脱我的任务,在那里,我们将制作一个2行的表,在默认视图中只有一行,因为最后一行是隐藏的(显示:无),然后当你将鼠标悬停在表格第二行会出现,我不知道我的CSS有什么错误?你觉得这行CSS是我错误的来源吗#table div.row:hover {display:table-row;},谢谢你的到来.