这是一个代码点火器中的控制器,我在运行函数get_reunits()时遇到了函数marge_orderfun()的问题。当我使用输出中的get_reunits() ( print_r in output,print_r($hotel_data);)运行函数时,我给出了以下输出(这正是我想要的):
Array (
[0] => Array (
[name] => 11
[price] => 77192276
[extra] => 11
[hotel_id] => 77192276
)
[1] => Array (
[name] => 11
[price] => 77192276
[extra] => 11
[hotel_id] => 77192276
)
) Array (
[0] => Array (
[name] => 666666666
[price] => 15190364
[extra] => 11
[hotel_id] => 15190364
)
[1] => Array (
[name] => 99999
[price] => 15190364
[extra] => 11
[hotel_id] => 15190364
)
[2] => Array (
[name] => 777777
[price] => 15190364
[extra] => 11
[hotel_id] => 15190364
)
[3] => Array (
[name] => 1221
[price] => 15190364
[extra] => 11
[hotel_id] => 15190364
)
) Array (
[0] => Array (
[name] => 666666666
[price] => 11
[extra] => 33
[hotel_id] => 15183965
)
[1] => Array (
[name] => 99999
[price] => 11
[extra] => 33
[hotel_id] => 15183965
)
[2] => Array (
[name] => 777777
[price] => 11
[extra] => 33
[hotel_id] => 15183965
)
[3] => Array (
[name] => 1221
[price] => 11
[extra] => 33
[hotel_id] => 15183965
)
)当使用from return $hotel_data;进行输出并运行函数marge_orderfun()时,我得到以下输出:
{“重新单位”:{“名称”:“11”,“价格”:“77192276”,“额外”:“11”,"hotel_id":"77192276"},{“名称”:“11”,“价格”:“77192276”,“额外”:“11”,"hotel_id":"77192276"}}
这是我的控制器:
function get_reunits(){
//$tourf_id = $this->input->post('tour_name');
$tourf_id = '102';
$query_r = $this->db->order_by('id','desc')->get_where('tour_foreign_residence', array('relation' => $tourf_id));
foreach($query_r->result() as $idx=>$val){
$hotel_id = $val->hotel_id;
$query = $this->db->get_where('tour_foreign_units', array('hotel_id' => $hotel_id));
if($query->num_rows() > 0){
$hotel_data = array();
foreach ($query->result() as $index=>$row) {
$hotel_data[] = array(
'name' => $row->name,
'price' => $row->price,
'extra' => $row->extra,
'hotel_id' => $row->hotel_id
);
}
}else{
return 0;
}
//print_r($hotel_data);
return $hotel_data;
}
}
function marge_orderfun(){
//$guide = array('guide' => $this->get_gr());
//$residence = array('residence' => $this->get_residence());
$reunits = array('reunits' => $this->get_reunits());
echo json_encode(array_merge(/*$guide, $residence,*/$reunits));
}如何将marge_orderfun()中的输出作为get_reunits()中的print_r中的输出
发布于 2011-10-26 20:50:29
实际上,你输出的是两种不同的东西。print_r正在以可读的格式转储PHP数组的结构/内容。您的marge_orderfun正在转储一串恰好是JSON格式的文本。这个json字符串过去是一个PHP数组,但现在它只是一个文本块。
发布于 2011-10-26 21:19:21
也许这段代码有助于:
$a = array();
$b = print_r($a, true);
echo $b;https://stackoverflow.com/questions/7908745
复制相似问题