1

I have a array called $data['job_list'] which is as follows

Array
(
    [0] => Array
        (
            [job_id] => 2
            [job_title] => JQuery developer
            [job_desc] => Developer
            [job_slug] => 2-JQuery-developer
            [job_type] => 191
            [job_skill] => 2
            [job_salary] => 2
            [job_experience] => 1
            [company_name] => IGUTS
            [company_desc] => IGUTS is a fresh company
            [company_industry] => 24
            [company_address] => 35 Lawrence Street
            [company_state] => 35
            [company_city] => 650
            [user_id] => 1
            [concerned_fname] => Saswat
            [concerned_lname] => Routroy
            [contact] => 8961287928
            [date_of_post] => 26-04-2014
            [job_timestamp] => 1398517810
            [industry_id] => 191
            [industry_title] => Web Designer/Developer
            [p_cid] => 24
            [industry_slug] => 191-Web-Designer-Developer
            [industry_desc] => 
            [industry_image] => 
            [industry_priority] => 0
            [industry_timestamp] => 1396535046
        )

    [1] => Array
        (
            [job_id] => 1
            [job_title] => PHP developer
            [job_desc] => Developer
            [job_slug] => 1-PHP-developer
            [job_type] => 191
            [job_skill] => 1,2
            [job_salary] => 1
            [job_experience] => 1
            [company_name] => IGUTS
            [company_desc] => IGUTS Company
            [company_industry] => 24
            [company_address] => 35 Lawrence Street
            [company_state] => 35
            [company_city] => 650
            [user_id] => 1
            [concerned_fname] => Saswat
            [concerned_lname] => Routroy
            [contact] => 8961287928
            [date_of_post] => 18-04-2014
            [job_timestamp] => 1397842605
            [skill_id] => 2
            [skill_title] => JQuery
            [skill_slug] => 2-JQuery
            [industry] => 24
            [skill_timestamp] => 1397395987
        )

    [2] => Array
        (
            [job_id] => 2
            [job_title] => JQuery developer
            [job_desc] => Developer
            [job_slug] => 2-JQuery-developer
            [job_type] => 191
            [job_skill] => 2
            [job_salary] => 2
            [job_experience] => 1
            [company_name] => IGUTS
            [company_desc] => IGUTS is a fresh company
            [company_industry] => 24
            [company_address] => 35 Lawrence Street
            [company_state] => 35
            [company_city] => 650
            [user_id] => 1
            [concerned_fname] => Saswat
            [concerned_lname] => Routroy
            [contact] => 8961287928
            [date_of_post] => 26-04-2014
            [job_timestamp] => 1398517810
            [skill_id] => 2
            [skill_title] => JQuery
            [skill_slug] => 2-JQuery
            [industry] => 24
            [skill_timestamp] => 1397395987
        )

)

[job_id] => 2 is present twice

What I want is that, the row with duplicate job_id => 2 should be removed

How can I achieve that??

1

3 Answers 3

2
$jobIds = array();

foreach ($jobs as $key => $job) {
    if (in_array($jobIds, $job['job_id'])) {
        unset($jobs[$key]);
        continue;
    }
    $jobIds[] = $job['job_id'];
}

print_r($jobs);
Sign up to request clarification or add additional context in comments.

Comments

0

I would cycle though each "job" and create an array of Job IDs. If I see the same ID twice then I would remove the duplicate and store it somewhere else if needed.

Comments

0

As Matei Mihai stated, i made some minor changes in his script and bingo it solved..

Matei Mihai made a mistake regarding the data-type of arguments of the in_array() function

I fixed that.

here's my code

    $jobIds = array();

    for($i = 0;$i < count($data['job_list']); $i++ )
    {
        if (in_array($data['job_list'][$i]['job_id'], $jobIds))
            {
                unset($data['job_list'][$i]);
                continue;
            }
        $jobIds[] = $data['job_list'][$i]['job_id'];
    }

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.