【发布时间】:2016-11-24 22:01:39
【问题描述】:
好吧,我得到了一个相当大的数据数组,现在除了 1 件事之外一切都很好,我想用空格替换数组中的所有点(例如,“Element.ID.Name”将变为“Element ID Name”现在我必须为此使用array_map,我怎么能做到这一点?我试过了
$filtered = array_map(array($this, 'clearDots'),$unfiltered); //calls the $this->clearDots
但我完全不确定要将什么代码放入 clearDots 函数中......
private function clearDots($arr) {
}
编辑:我试着用
str_replace("."," ",$variable);
但这只是替换数组中的所有文本而不是替换点
编辑 2: 这是它未经过滤的部分
$unfiltered[] = $row['row_name'];
这就是我将东西推入该数组的方式
这是完整的代码
public function getAll() {
$sql = $this->conn();
$result = $sql->query("SELECT row_name FROM tab");
if($result->num_rows >= 1) {
while($row = $result->fetch_assoc()) {
$unfiltered[] = $row['row_name'];
}
}
$filtered = array_map(array($this, 'clearDots'),$unfiltered);
print json_encode($filtered);
}
private function clearDots($variable) {
str_replace("."," ",$variable);
}
【问题讨论】: