0

I have situation . I want to insert one array element to another array element but could not find the exact method.

This is my function

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 result show this.

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 show like this.

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

I want to insert these these elements iteration wise. When in the educations first iteration comes than it should insert all the elements at one index of second array separated by comma.

1
  • Can you give me example array do you want? Commented Aug 10, 2016 at 6:20

1 Answer 1

1

If I understand your question correctly then following might help. It will insert comma separated values from $getid into new key called "getid" in $educations array.

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);
}

Hope this helps and this is what you want

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.