我想在数组中创建描述摘要,因为它充当了完整帖子的链接。
所以举个例子。 “我今天去公园”会变成“我去了......”
我尝试了以下内容但没有取得任何成功。
我需要更改的数组是$ description []
foreach ($description as $descriptions) {
$descriptions = substr($descriptions, 0, 12);
$description = ($description + '...');
}
答案 0 :(得分:0)
使用array_walk
直接修改数组中的元素..
array_walk($description,function (&$v){ $v=substr($v, 0, 12)."...";});
答案 1 :(得分:0)
尝试此操作并使用新变量$desc
$desc = array();
foreach ($description as $descriptions) {
$desc[] = substr($descriptions, 0, 12).'...';
}
答案 2 :(得分:0)
你应该这样做:
$descriptions = array('something' => 'I went to the park today');
foreach ($descriptions as $index => $value) {
$value = substr($value, 0, 12);
$descriptions[$index] = ($value . '...');
}
现在,$descriptions
将为Array ( [something] => I went to th... )
答案 3 :(得分:0)
尝试以下。
foreach ($description as $descriptions) {
$descriptions = substr($descriptions, 0, 12);
$descriptions = ($descriptions . '...');
}