Hello Everyone我在php中有一个数组,如
array (size=2)
0 => string 'A6,A5,B12,B11,' (length=14)
1 => string 'B6,B5,B8,B7,' (length=12)
on var_dump($ arr)。我怎么能把它转换成类似
的东西 array('A6,A5,B12,B11,B6,B5,B8,B7,')
在PHP中这是我正在做的事情,以获得上面的数组
$id= "1";
$data['busInfo']= $this->dashboard_model->find_bus($id);
$data['reservationInfo'] = $this->dashboard_model->get_booked_seats_info($id);
$arr =array();
foreach ($data['reservationInfo'] as $reserved){
$seatBooked = $reserved->seats_numbers;
array_push($arr, $seatBooked);
}
var_dump($arr);
我正在使用Codeigniter作为我的框架。
答案 0 :(得分:0)
你可以只追加一个字符串,然后用该字符串创建一个单独的元素数组(如果你真的需要一个数组):
$data['reservationInfo'] = $this->dashboard_model->get_booked_seats_info($id);
$str='';
foreach ($data['reservationInfo'] as $reserved){
$str .= $reserved->seats_numbers;
}
var_dump(array($str));
或者只是内爆源数组:
var_dump(array(implode('', $this->dashboard_model->get_booked_seats_info($id))));