我想在for-each循环中从数组中删除最后几个字母。我正在尝试显示没有bl_date
的{{1}}。现在显示/2018
。怎么回声像这样的07/10/2018 & 06/30/2018
?
数组
07/10 & 06/30
PHP
Array
(
[0] => stdClass Object
(
[id] => 18
[bl_user] => 61
[bl_date] => 07/10/2018
)
[1] => stdClass Object
(
[id] => 17
[bl_user] => 61
[bl_date] => 06/30/2018
)
)
答案 0 :(得分:0)
一种选择是使用substr()
删除字符串的后5个字符
赞:
$resultstr = array();
foreach ($billings as $billing) {
$resultstr[] = substr( $billing->bl_date, 0, -5 );
}
echo implode(" & ",$resultstr);
这将导致:
07/10 & 06/30
文档:substr()
答案 1 :(得分:0)
您需要使用substr函数:
foreach ($billings as $billing) {
$resultstr[] = substr($billing->bl_date, 0, 5);
}