I have an array like this
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>
}
Hope to convert it into an array like this
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>
}
}
Can anyone help me solve this problem? Thank you very much
I have an array like this
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>
}
Hope to convert it into an array like this
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>
}
}
Can anyone help me solve this problem? Thank you very much
The whole rough but clear way is as follows
<code>$tmp = ''; foreach ($array as $key=>$val){ $tmp .= $val['flow_name'].'---'; } $tmp = rtrim($tmp, '---'); $new = $array[0]; $new[0]['flow_name'] = $tmp;</code>
Haha...
Try to use PHP’s built-in functions to be more efficient
<code class="php">$temp = $arr[0]; $temp['flow_name'] = join('---', array_column($arr, 'flow_name'));</code>
This is not simple
<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>