我目前正在使用以下数组
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] => 01234 567890
[contact_email] => barney@bluepeter.co.uk
[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] => simonainley@the-factory.co.uk
[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>
我做错了什么?
答案 0 :(得分:0)
这给你带来了什么?
<?php foreach ($candidates as $k => $v) print_r($v); ?>
我不知道如果给定该数组定义$ v [&#39; id&#39;],那么还有其他的东西会被遗漏...... < / p>
你正在使用site_url()......我闻到了CodeIgniter吗? ;)
答案 1 :(得分:0)
你的数组对于那个循环太深了。我假设$candidates
是整个大数组的名称?您不需要在自己的数组中使用每个候选项,尝试将结果放在一个级别较低的数组中,foreach
将起作用。
答案 2 :(得分:0)
<?
for($i=0; $i=50; $i++){
foreach ($candidates[$i] as $v){
?>
<li><a href="<?php echo site_url(); ?>candidates/card/id/<?php echo $v[0]['candidate_id']; ?>"><?php echo $v[0]['first_name']. " ".$v[0]['surname']; ?></a></li>
<?
}
}
?>