如何从数组中打印特定值?
这是我的代码
<?php
$custom_fields = get_custom_fields('projects');
if(count($custom_fields) > 0){ ?>
<?php foreach($custom_fields as $field){ ?>
<?php $value = get_custom_field_value($project->id,$field['id'],'projects');
if($value == ''){continue;} ?>
<tr>
<td class="bold"><?php echo ucfirst($field['name']); ?></td>
<td><?php echo $value; ?></td>
</tr>
<?php } ?>
<?php } ?>
这是我的功能:
function get_custom_field_value($rel_id, $field_id, $field_to, $format = true)
{
$CI =& get_instance();
$CI->db->where('relid', $rel_id);
$CI->db->where('fieldid', $field_id);
$CI->db->where('fieldto', $field_to);
$row = $CI->db->get('tblcustomfieldsvalues')->row();
$result = '';
if ($row) {
$result = $row->value;
if ($format == true) {
$CI->db->where('id', $field_id);
$_row = $CI->db->get('tblcustomfields')->row();
if ($_row->type == 'date_picker') {
$result = _d($result);
}
}
}
return $result;
}
如果我print_r(array_values($custom_fields));
我得到了:
数组([0] =&gt;数组([id] =&gt; 5 [fieldto] =&gt;项目[名称] =&gt;汽车品牌[slug] =&gt; projects_car_brand [必需] =&gt; 1 [类型] =&gt;选择[选项] =&gt; Abarth,Acura,阿尔法罗密欧,阿斯顿马丁,奥迪,奥斯汀,宾利,宝马,布加迪,别克,凯迪拉克,雪佛兰,克莱斯勒,雪铁龙,克尔维特,达契亚,大宇,大发,戴姆勒,道奇,法拉利,菲亚特,福特,本田,现代,英菲尼迪,五十铃,捷豹,吉普,起亚,Koenigsegg,兰博基尼,蓝旗亚,路虎,雷克萨斯,林肯,莲花,玛莎拉蒂,迈巴赫,马自达,迈凯轮,梅赛德斯,MG ,迷你,三菱,摩根,日产,欧宝,标致,庞蒂亚克,保时捷,雷诺,劳斯莱斯,路虎,萨博,接穗,西亚特,斯柯达,智能,双龙,斯巴鲁,铃木,特斯拉,丰田,沃克斯豪尔,大众,沃尔沃[field_order] =&gt; 0 [有效] =&gt; 1 [show_on_pdf] =&gt; 0 [only_admin] =&gt; 0 [show_on_table] =&gt; 1 [show_on_client_portal] =&gt; 1 [disalow_client_to_edit] =&gt; 1 [ bs_column] =&gt; 12)[1] =&gt;数组([id] =&gt; 6 [fieldto] =&gt; projects [name] =&gt; Car Model [slug] =&gt; projects_car_model [required] =&gt; 1 [type] =&gt;输入[选项] =&gt; [field_order] =&gt; 0 [有效] =&gt; 1 [show_on_pdf] =&gt; 0 [only_admin] =&gt; 0 [show_on_table] =&gt; 1 [show_on_client_portal] =&gt; 1 [disalow_client_to_edit] =&gt; 1 [bs_column] =&gt; 12))
我想在[options]字段下为第一个数组存储值。