Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:37:18+00:00 2026-05-23T16:37:18+00:00

Hello I have an array that looks like this after passing it through uksort()

  • 0

Hello I have an array that looks like this after passing it through uksort()

    Array
(
    [3] => Array
        (
            [job_id] => 4
            [job_title] => Supercar Test Driver
            [company_name] => McLaren
            [logo_small] => small_mclaren001.png
            [logo_large] => large_mclaren002.png
            [employer_id] => 3
        )

    [2] => Array
        (
            [job_id] => 3
            [job_title] => Recruitment Consultant - Driving
            [company_name] => MoovJob.com
            [logo_small] => small_rac001.png
            [logo_large] => large_rac002.png
            [employer_id] => 2
        )

    [1] => Array
        (
            [job_id] => 5
            [job_title] => Postal Worker / Post Person
            [company_name] => Royal Mail
            [logo_small] => small_royalmail001.png
            [logo_large] => large_royalmail002.png
            [employer_id] => 4
        )

    [0] => Array
        (
            [job_id] => 6
            [job_title] => Another Job
            [company_name] => MoovJob.com
            [logo_small] => small_rac001.png
            [logo_large] => large_rac002.png
            [employer_id] => 2
        )

)

However if in my SQL that returns this array I add GROUP BY company_name the final entry in the array dissapears, what I am trying to achieve is to place the job title under the company name, but only show the company name once, something similar to this,

Company Name 1
Job Title 1
Job Title 2
Job Title 3

Company Name 2
Job Title 4

Company Name
Job Title 5 Job Title 6

I am trying to achieve this, by doing the followng in my view, however I can only show one vacancy, what am I doing wrong?

    <?php $oldemp   = "";?>
<?php foreach($jobs as $key => $value) : ?>
   <?php if ($oldemp != $value['company_name']) : ?>
        <?php $oldemp = $value['company_name']; ?>
        <section class="employer">
            <div class="job_holder">
                <img src="<?php echo base_url(); ?>media/uploads/users/<?php echo $value['logo_large']; ?>" width="198" height="148" alt="<?php echo $value['company_name']; ?>"/>
                <dl>
                    <dt><?php echo count($key); ?></dt>
                    <dd>Matches</dd>
                </dl>
    <?php endif;?>
            <span> + <a href="/jobwall/getjob/<?php echo $value['job_id']; ?>"><?php echo $value['job_title']; ?></a></span>
            </div>
        </section>
<?php endforeach; ?>


    function jobcmp($job1, $job2)
    {
        return strcmp($job1['company_name'], $job2['company_name']);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:37:19+00:00Added an answer on May 23, 2026 at 4:37 pm

    Although it would be possible to display the data using your approach I normally find it much more straightforward to create a second array in a more convenient format:

    $groupedJobs = array();
    foreach ($jobs as $data) {
        if (!isset($groupedJobs[$data['company_name']])) {
            $groupedJobs[$data['company_name']] = array();
        }
        $groupedJobs[$data['company_name']][] = $data;
    }
    

    this creates a new array using the company name as the key and that company’s jobs in a nested array as the value, giving you something like this:

    ['MoovJob.com'] => Array
        (
            [0] => Array
                (
                    (job data)
                ),
            [1] => Array 
                (
                    (etc.)
                )
        ),
    ['McLaren'] = Array
        (
            (etc)
        )
    

    it is then much easier to loop through this array and display:

    foreach ($groupedJobs as $companyName => $jobs) {
        echo $companyName;
        foreach ($jobs as $job) {
            echo $job['job_title'].'<br />';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have an array that looks like this, Array ( [cfi_title] => Mr
I have an array that looks something like this array(7) { [0]=> hello,pat1 [1]=>
I have a PHP array that looks like this: [3] => Hello [7] =>
I have a data structure that looks like this: [ {:choices=>[Hello, Hi]}, , {:choices=>[wor,
I have written this code that loops through an array of lat/long coordinates and
I have a string that looks like: '- 10 TEST (FOO 3 TEST.BAR 213
I have an array that looks like [products] => Array ( [0] => stdClass
Hello fellow programmers, I have made a function that looks up the database if
I want to split a string in C#.NET that looks like this: string Letters
Hello i have this foreach loop that gives weird result , it displays only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.