我目前有以下陣列工作循環,通過數組的數組
Array
(
[0] => Array
(
[0] => Array
(
[candidate_id] => 41
[show_on_site] => urban talent
[first_name] => Barney
[surname] => Harwood
[gender] => male
[talent] => presenter
[skill] =>
[DOB] => 1983-11-30
[Location] => London
[contact_telephone] =>
[contact_email] => [email protected]
[height] => 5' 1"
[eyes] => Brown
[hair_colour] => brown
[hair_length] => medium
[accents] => Native Northern, others include - Yorkshire, Liverpool, Manchester, Birmingham, Cockney, RP, Welsh, Scottish, German, American
[training] => n/a
[unions] => Member of the British Academy of Composers & Songwriters
Equity & MU Member
[visible] => yes
[availability] => yes
[availability_number] => 9999
[availability_order] => 0
[availability_comments] => BARNEY IS THE LATEST BLUE PETER PRESENTER AND CAN BE SEEN ON AIR MONDAYS & TUESDAYS AT 4.30PM ON BBC
[spotlight_url] =>
[youtube_showreel] =>
[date_created] => 2011-11-02 10:44:37
[created_by] => 1
)
)
[1] => Array
(
[0] => Array
(
[candidate_id] => 42
[show_on_site] => urban talent
[first_name] => Simon
[surname] => Ainley
[gender] => male
[talent] => actor
[skill] =>
[DOB] => 1987-06-12
[Location] => Huddersfield
[contact_telephone] => 01484 532751
[contact_email] => [email protected]
[height] => 5' 1"
[eyes] => blue
[hair_colour] => brown
[hair_length] => short
[accents] => Accents
[training] => Training
[unions] => Union Membership
[visible] => yes
[availability] => yes
[availability_number] => 9999
[availability_order] => 0
[availability_comments] => Availability Comments
[spotlight_url] => http://www.google.com
[youtube_showreel] => http://www.youtube.com/watch?v=sP4NMoJcFd4
[date_created] => 2011-11-08 11:28:12
[created_by] => 1
)
)
)
,你可以看到它是一個數組類型的情況中的數組,我想遍歷它拉出來在first_name
+ surname
每個條目的,但我得到以下錯誤,當我嘗試這樣做,
A PHP Error was encountered
Severity: Notice
Message: Undefined index: firstname
Filename: admin/candidate_list.php
Line Number: 5
我通過它循環這樣的時刻,
<?php foreach ($candidates as $k => $v) : ?>
<li><a href="<?php echo site_url(); ?>candidates/card/id/<?php echo $v['id']; ?>"><?php echo $v[0]['first_name']. " ".$v[0]['surname']; ?></a></li>
我在做什麼錯?
你需要的是嵌套循環。循環內循環 – Ibu
你確定你的代碼是最新的嗎?根據你想要訪問'$ v ['firstname']'而不是'$ v ['first_name']'的錯誤。 –
@ sico87:很難從您提供的代碼中分辨出來。你能告訴我們你如何定義'候選人'嗎? –