2016-08-10 14 views
0

私は状況があります。私は別の配列要素に1つの配列要素を挿入したいが、正確なメソッドを見つけることができませんでした。最後の配列に配列インデックスを挿入する

これは

public function get_applicants($sort_array = array('apply_id DESC')) 
{ 
    global $wpdb; 
    $sql = 'SELECT * FROM ' . $this->tableac . " ORDER BY " . implode(',', $sort_array); 
    //$sql = 'SELECT c. * , p. * FROM wp_apply c, wp_apply_files p WHERE c.apply_id = p.apply_id'; 
    $educations = $wpdb->get_results($sql); 
    $getid=array(); 
    foreach($educations as $education){ 
     //print_r($education); 
     $sqlfile = 'SELECT * FROM wp_apply_files WHERE apply_id = '.$education->apply_id; 
     $getalls = $wpdb->get_results($sqlfile); 
     $allvalues=""; 
      foreach($getalls as $getall){ 
       $allvalues= $getall->uploaded_file.", "; 
       $getid[]=$getall->uploaded_file; 
      } 
      $allvaluesnew=rtrim($allvalues,", "); 
     // echo "<br>"; 
     // Here I want to insert getid into educations array 
    } 
    echo "<pre>";print_r($educations); 
    die(); 
    //return array($educations,$getid); 
} 

ますprint_r結果はこれを示す私の関数です。

Array 
(
[0] => stdClass Object 
    (
     [apply_id] => 44 
     [choose_position] => HR Manager 
     [title] => testr 
     [first_name] => waqas 
     [last_name] => aamer 
     [current_job] => developer 

print_r get idはこのように表示されます。

Array 
(
[0] => a75d138911c55df639fdd09fade511151-23.pdf 
[1] => newone3.pdf 
[2] => a75d138911c55df639fdd09fade511151-22.pdf 
[3] => newone2.pdf 
[4] => a75d138911c55df639fdd09fade511151 (2).pdf 
[5] => newone.pdf 
) 

これらの要素を繰り返し挿入する必要があります。最初の反復は、すべての要素をコンマで区切られた2番目の配列の1つのインデックスに挿入する必要があります。

+0

欲しいものです

public function get_applicants($sort_array = array('apply_id DESC')) { global $wpdb; $sql = 'SELECT * FROM ' . $this->tableac . " ORDER BY " . implode(',', $sort_array); //$sql = 'SELECT c. * , p. * FROM wp_apply c, wp_apply_files p WHERE c.apply_id = p.apply_id'; $educations = $wpdb->get_results($sql); $getid=array(); foreach($educations as $key => $education){ //print_r($education); $sqlfile = 'SELECT * FROM wp_apply_files WHERE apply_id = '.$education->apply_id; $getalls = $wpdb->get_results($sqlfile); foreach($getalls as $getall){ $getid[]=$getall->uploaded_file; } // echo "<br>"; // Here I want to insert getid into educations array $educations[$key]["getid"] = implode(",", $getid); } echo "<pre>";print_r($educations); die(); //return array($educations,$getid); } 

ホープあなたは私の例の配列を与えることができ、あなたはしたいですか? – user5200704

答えて

1

私があなたの質問を正しく理解していれば、次のように役立つかもしれません。 のコンマ区切りの値を、$educations配列の「getid」という新しいキーに挿入します。このことができますし、これはあなたが

関連する問題