Php 如何将函数数组按行拆分?
我在codeigniter中有一个php函数,它从我的数据库中获取数据:Php 如何将函数数组按行拆分?,php,arrays,database,codeigniter,Php,Arrays,Database,Codeigniter,我在codeigniter中有一个php函数,它从我的数据库中获取数据: function fetch_data() { $data = $this->projectionchart_model->make_query(); $array = array(); foreach($data as $row) { $array[] = $row; } $output = array( 'current' =
function fetch_data()
{
$data = $this->projectionchart_model->make_query();
$array = array();
foreach($data as $row)
{
$array[] = $row;
}
$output = array(
'current' => intval($_POST["current"]),
'rowCount' => 10,
'total' => intval($this->projectionchart_model->count_all_data()),
'rows' => $array
);
echo json_encode($output);
}
我想对一些列使用number\u格式
函数,现在它正在数组中构建所有内容。如何删除数组并将数据单独列为变量,以便对其中一些应用函数,然后输出它们
多谢各位
编辑:更详细地解释
此函数fetch_data()调用projectionchart_模型文件中存储的make_query()函数,该文件包含以下内容:
function make_query()
{
if(isset($_POST["rowCount"]))
{
$this->records_per_page = $_POST["rowCount"];
}
else
{
$this->records_per_page = 10;
}
if(isset($_POST["current"]))
{
$this->current_page_number = $_POST["current"];
}
$this->start_from = ($this->current_page_number - 1) * $this->records_per_page;
$this->db->select("*");
$this->db->from("projection_chart");
if(!empty($_POST["searchPhrase"]))
{
$this->db->like('ae', $_POST["searchPhrase"]);
$this->db->or_like('client', $_POST["searchPhrase"]);
$this->db->or_like('product', $_POST["searchPhrase"]);
$this->db->or_like('week_of', $_POST["searchPhrase"]);
$this->db->or_like('month', $_POST["searchPhrase"]);
$this->db->or_like('type', $_POST["searchPhrase"]);
}
if(isset($_POST["sort"]) && is_array($_POST["sort"]))
{
foreach($_POST["sort"] as $key => $value)
{
$this->db->order_by($key, $value);
}
}
else
{
$this->db->order_by('id', 'DESC');
}
if($this->records_per_page != -1)
{
$this->db->limit($this->records_per_page, $this->start_from);
}
$query = $this->db->get();
return $query->result_array();
}
因此,当前的输出是:
我想用number_format php函数格式化计划支出、结清和总佣金,但现在它都在一个数组中
如何实现这一点?使用变量声明?o、 o不确定你在问什么…@treyBake like$row['data'];?类似于
$row['data']=number\u格式($row['data'],2)
为了澄清您的问题并使其更易于回答,您能否给出一个函数当前生成的输出的简要示例,一个您希望它生成的输出的示例,以及对更改的解释?@Don'tPanic我刚刚更新了帖子来解释我想说的内容