帮助循环遍历数组

时间:2011-07-04 22:14:40

标签: php arrays foreach

  

可能重复:
  help with looping through an array

你好,我有一个看起来像这样的数组,

    Array (
    [0] => Array
        (
            [job_id] => 5
            [job_title] => Postal Worker / Post Person
            [salary] => 25000
            [job_tags] => Transport & Logistics
            [retrain] => no
            [job_extras] => Fantastic Pension Scheme, 32 Days Holiday, Health Insurance
            [job_summary] => The successful candidate will enjoy the benefits of working for a growing company on a successful and fast paced desk.  You will receive a good salary and excellent uncapped commission structure.
            [job_description] => My clients are a well established recruitment consultancy with over 30 UK branches and they were recently voted the ‘Number 1 General Recruiter’ by Recruit Magazine.  Founded in 1986 they provide personnel to the commercial, construction, driving, finance, industrial and IT industries and offer temporary, contract and permanent placements to fulfil any requirement.  As a company they have experienced astounding growth which has lead them to becoming the first choice for many candidates, supplying a reservoir of fresh positions across all of their sectors. As a company they hold the opinions of their clients and candidates in high regard and work tirelessly to provide a high quality service that is flexible, trustworthy and reliable.  Their experienced consultants work efficiently to match the needs of their clients with the abilities of their first rate candidates and hit the mark first time, saving money and aiding in the productivity of all involved.  They implement training and support to their consultants to enhance the service they are able to provide and to ensure they always have their finger on the pulse of current market trends.   They are currently recruiting for a Recruitment Consultant to join the company on a driving desk.   You will be an experienced consultant with a background in driving recruitment.  You must possess strong sector knowledge and will have excellent business development skills as although this desk is warm it needs additional development from an individual with dedication and motivation to achieve its maximum potential.  This is a very lucrative sector and although business development will be an essential element of your role, it will be a relatively yielding task.  This is a temporary desk with many candidates and a fast turnaround; you will be confident in all aspects of running a temporary desk.  You must be capable of a 360 role and will possess excellent personal management skills.  Able to work as part of a team and autonomously, you will be a focused and positive individual with a professional demeanour.  This position has notable opportunities for progression as the company has many plans for growth within this sector.  An ambitious and hard working applicant could achieve great rewards. The successful candidate will enjoy the benefits of working for a growing company on a successful and fast paced desk.  You will receive a good salary and excellent uncapped commission structure.
            [company_name] => Royal Mail
            [company_summary] => Company Summary Here
            [logo_small] => small_royalmail001.png
            [logo_large] => large_royalmail002.png
            [employer_id] => 4
        )

    [1] => Array
        (
            [job_id] => 3
            [job_title] => Recruitment Consultant - Driving
            [salary] => 24000
            [job_tags] => Recruitment, Sales, Transport
            [retrain] => no
            [job_extras] => Company Car, Pension Scheme, Generous Bonus Of Up To £12'000
            [job_summary] => My clients are a well established recruitment consultancy with over 30 UK branches and they were recently voted the "Number 1 General Recruiter" by Recruit Magazine.  Founded in 1986 they provide personnel to the commercial, construction, driving, finance, industrial and IT industries and offer temporary, contract and permanent placements to fulfil any requirement.
            [job_description] => As a company they have experienced astounding growth which has lead them to becoming the first choice for many candidates, supplying a reservoir of fresh positions across all of their sectors.  As a company they hold the opinions of their clients and candidates in high regard and work tirelessly to provide a high quality service that is flexible, trustworthy and reliable.  Their experienced consultants work efficiently to match the needs of their clients with the abilities of their first rate candidates and hit the mark first time, saving money and aiding in the productivity of all involved.  They implement training and support to their consultants to enhance the service they are able to provide and to ensure they always have their finger on the pulse of current market trends.   They are currently recruiting for a Recruitment Consultant to join the company on a driving desk.   You will be an experienced consultant with a background in driving recruitment.  You must possess strong sector knowledge and will have excellent business development skills as although this desk is warm it needs additional development from an individual with dedication and motivation to achieve its maximum potential.  This is a very lucrative sector and although business development will be an essential element of your role, it will be a relatively yielding task.  This is a temporary desk with many candidates and a fast turnaround; you will be confident in all aspects of running a temporary desk.  You must be capable of a 360 role and will possess excellent personal management skills.  Able to work as part of a team and autonomously, you will be a focused and positive individual with a professional demeanour.  This position has notable opportunities for progression as the company has many plans for growth within this sector.  An ambitious and hard working applicant could achieve great rewards. The successful candidate will enjoy the benefits of working for a growing company on a successful and fast paced desk.  You will receive a good salary and excellent uncapped commission structure.   For further details please contact Jo at Andbridge Associates on 01332 223954 / 07432
096582.  For similar sector or other sector vacancies, please visit the Andbridge Associates website for full listings.
            [company_name] => MoovJob.com
            [company_summary] => Company Summary Goes Here...
            [logo_small] => small_rac001.png
            [logo_large] => large_rac002.png
            [employer_id] => 2
        )

    [2] => Array
        (
            [job_id] => 4
            [job_title] => Supercar Test Driver
            [salary] => 40000
            [job_tags] => Driving
            [retrain] => no
            [job_extras] => Pension, 30 Days Holiday, Continental Shift (3 Days Off 3 Days On)
            [job_summary] => You will be an experienced consultant with a background in driving recruitment.  You must possess strong sector knowledge and will have excellent business development skills as although this desk is warm it needs additional development from an individual with dedication and motivation to achieve its maximum potential.
            [job_description] => My clients are a well established recruitment consultancy with over 30 UK branches and they were recently voted the ‘Number 1 General Recruiter’ by Recruit Magazine.  Founded in 1986 they provide personnel to the commercial, construction, driving, finance, industrial and IT industries and offer temporary, contract and permanent placements to fulfil any requirement.  As a company they have experienced astounding growth which has lead them to becoming the first choice for many candidates, supplying a reservoir of fresh positions across all of their sectors. As a company they hold the opinions of their clients and candidates in high regard and work tirelessly to provide a high quality service that is flexible, trustworthy and reliable.  Their experienced consultants work efficiently to match the needs of their clients with the abilities of their first rate candidates and hit the mark first time, saving money and aiding in the productivity of all involved.  They implement training and support to their consultants to enhance the service they are able to provide and to ensure they always have their finger on the pulse of current market trends.   They are currently recruiting for a Recruitment Consultant to join the company on a driving desk.   You will be an experienced consultant with a background in driving recruitment.  You must possess strong sector knowledge and will have excellent business development skills as although this desk is warm it needs additional development from an individual with dedication and motivation to achieve its maximum potential.  This is a very lucrative sector and although business development will be an essential element of your role, it will be a relatively yielding task.  This is a temporary desk with many candidates and a fast turnaround; you will be confident in all aspects of running a temporary desk.  You must be capable of a 360 role and will possess excellent personal management skills.  Able to work as part of a team and autonomously, you will be a focused and positive individual with a professional demeanour.  This position has notable opportunities for progression as the company has many plans for growth within this sector.  An ambitious and hard working applicant could achieve great rewards. The successful candidate will enjoy the benefits of working for a growing company on a successful and fast paced desk.  You will receive a good salary and excellent uncapped commission structure.
            [company_name] => McLaren
            [company_summary] => Company Summary Here
            [logo_small] => small_mclaren001.png
            [logo_large] => large_mclaren002.png
            [employer_id] => 3
        )

)

使用PHP,我如何遍历数组以获得以下结果

雇主姓名 - 所有具有该雇主姓名的职位 雇主姓名 - 所有具有该雇主姓名的工作。

我目前的尝试看起来像这样,

<?php if(is_array($jobs)) : ?>
<?php $count = count($jobs); ?>
<?php $employerCache = ''; ?>
<?php foreach ($jobs as $j) : ?>
    <?php if ($j['company_name'] != $employerCache) : ?>
          <section class="employer">
            <div class="job_holder">
                <img src="<?php echo base_url(); ?>media/uploads/users/<?php echo $j['logo_large']; ?>" width="198" height="148" alt="<?php echo $j['company_name']; ?>"/>
                <dl>
                    <dt><?php echo $count; ?></dt>
                    <dd>Matches</dd>
                </dl>
                <!--<a href="" class="fave">Fave</a>-->
                 <ul class="job_listings">
                        <?php foreach ($jobs as $j) : ?>
                            <?php $job = $j['job_title']; ?>
                            <li>
                                + <a href="<?php echo base_url(); ?>jobwall/getjob/<?php echo $j['job_id']; ?>" class="openjob">
                                    <?php echo $job; ?>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
            </div>
        </section>
           <?php $employerCache = $j['company_name']; ?>
    <?php endif; ?>
<?php endforeach;?>    
    <?php else : ?>
    <section class="success">
        <h4>There are currently no jobs listed. If you think you are seeing this message in error please contact move job</h4>
    </section>
<?php endif;?>

0 个答案:

没有答案
相关问题