2017-05-30 83 views
0

我有這種類型的數組,我想隱蔽了一些要素,以逗號separeted轉換數組元素轉換成以逗號分隔的數組中的PHP

Array 
(
    [0] => Array 
     (
      [tution_provider] => sd 
      [app_subject_name] => KE2-Management Accounting Information 
      [exam_activity] => 734 
      [icasl_no] => 1746828 
      [app_subject_id] => 1013 
      [exam_session] => 000091 
      [id] => 724 
     ) 

    [1] => Array 
     (
      [tution_provider] => sdfsdf 
      [app_subject_name] => KE3B-Fundamentals of Law 
      [exam_activity] => 734 
      [icasl_no] => 1746828 
      [app_subject_id] => 1016 
      [exam_session] => 000091 
      [id] => 725 
     ) 

    [2] => Array 
     (
      [tution_provider] => sdfsdfsdf 
      [app_subject_name] => KE4-Processes, Assurance & Ethics 
      [exam_activity] => 734 
      [icasl_no] => 1746828 
      [app_subject_id] => 1017 
      [exam_session] => 000091 
      [id] => 726 
     ) 

) 

我想離開從

app_subject_id

作爲逗號分隔的數組。我怎樣才能做到這一點?

這是出放,我想

陣列([0] => 1013 [1] => 1016 [2] => 1017 [3] => 1013 [4] => 1016 [5 ] => 1017)

+0

請更新您的預期輸出。 –

+0

嗯你是指索引數組而不是關聯數組? –

+0

[將關聯數組更改爲索引數組/獲取Zend \ _Table \ _Row \ _Abstract作爲非關聯]可能的副本(https://stackoverflow.com/questions/1065131/change-an-associative-array-into -an-indexed-array-get-an-zend-table-row-abstra) –

回答

5
$array = array_column($array, 'app_subject_id'); //Get an array of just the app_subject_id column 
$array = implode(',', $array); //creates a string of the id's separated by commas 

輸出:

1013,1016,1017 
0

最後我已經這樣做了,感謝您的大力支持。

 $subjctss = $myarray; 

    if (!empty($subjctss)) { 

             $subid_arr = array(); 
             foreach ($subjctss as $values) { 
              $app_sub = $values['app_subject_id']; 
              $subid_arr[] = $app_sub; 

              echo '<ul><li>' . $values['app_subject_name'] . '</li> 

          </ul>'; 
             } 
             if (!empty($subid_arr) && is_array($subid_arr)) { 
//           $app_sub_comma_seprated = implode(',', $subid_arr); 
              print_r($subid_arr); 
             } 
            } 
相關問題