我有這樣一個陣列
array(97) {
[0] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(15) "预约核名号" ["work_id"] => string(1) "1"</code>
}
[1] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(18) "办理名称核准" ["work_id"] => string(1) "1"</code>
}
[2] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(15) "预约受理号" ["work_id"] => string(1) "1"</code>
}
[3] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(18) "办理三证合一" ["work_id"] => string(1) "1"</code>
}
[4] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(12) "刻章备案" ["work_id"] => string(1) "1"</code>
}
希望轉換成這樣的陣列
array{
[0] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(12) "预约核名号---办理名称核准---预约受理号---办理三证合一----刻章备案" ["work_id"] => string(1) "1"</code>
}
}
有大神朋友幫忙解決麼 感激不盡
我有這樣一個陣列
array(97) {
[0] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(15) "预约核名号" ["work_id"] => string(1) "1"</code>
}
[1] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(18) "办理名称核准" ["work_id"] => string(1) "1"</code>
}
[2] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(15) "预约受理号" ["work_id"] => string(1) "1"</code>
}
[3] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(18) "办理三证合一" ["work_id"] => string(1) "1"</code>
}
[4] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(12) "刻章备案" ["work_id"] => string(1) "1"</code>
}
希望轉換成這樣的陣列
array{
[0] => array(5) {
<code>["job_id"] => string(1) "1" ["job_name"] => string(18) "内资公司注册" ["work_name"] => string(12) "公司注册" ["flow_name"] => string(12) "预约核名号---办理名称核准---预约受理号---办理三证合一----刻章备案" ["work_id"] => string(1) "1"</code>
}
}
有大神朋友幫忙解決麼 感激不盡
整個比較粗但一目了然的方式,如下
<code>$tmp = ''; foreach ($array as $key=>$val){ $tmp .= $val['flow_name'].'---'; } $tmp = rtrim($tmp, '---'); $new = $array[0]; $new[0]['flow_name'] = $tmp;</code>
哈哈……
盡量使用PHP自帶函數,效率能高點
<code class="php">$temp = $arr[0]; $temp['flow_name'] = join('---', array_column($arr, 'flow_name'));</code>
這還不簡單
<code> // 先把flow_name全部拿出来 // 临时数组 $tmp_arr = []; foreach($data as $value){ // push到临时数组 $tmp_arr[] = $value['flow_name']; } $flow_name = join('---', $tmp_arr[]);</code>
<code>$data = [ [ 'flow_name' => '预约合约号' ], [ 'flow_name' => '办理名称核准' ], [ 'flow_name' => '预约受理号' ], [ 'flow_name' => '办理三证合一' ], [ 'flow_name' => '刻章备案' ] ]; $data = array_map(function ($item) { return $item['flow_name']; }, $data); echo join('---',$data); exit;</code>