检查数组键是否存在

时间:2012-04-13 18:39:19

标签: php html arrays

我有以下代码循环遍历数组并构建我的html结构:

<?php foreach ($view->result as $id => $row): ?>
    <?php 
        $data = $row->field_field_slider_image;
        if (!count($data)) {
            continue;
        }
        //dpm($row);
        // add captions to an empty array
        if (isset($row->field_data_field_slider_image_field_slider_image_title)) {
            $captions["caption-fid-" . $row->field_data_field_slider_image_field_slider_image_fid] = '<div class="header"><h3>' 
            .   l($row->node_title, $row->field_field_slider_link[0]['raw']['url']) . '</h3></div><div class="body">'  
            .   drupal_render($row->field_body)
            . '</div>'
            . l(t('read more'), $row->field_field_slider_link[0]['raw']['url'], array('attributes' => array('class' => array('button_link'))));
        }

        $file = $data[0]['rendered'];
        // assign iamge style
        $style = isset($file['#image_style']) && !empty($file['#image_style']) ? $file['#image_style'] :
        variable_get('glossy_style_ff_slideshow', 'front_featured_slideshow_image');
    ?>
  <a href="<?php print url($row->field_field_slider_link[0]['raw']['url']); ?>"><img src="<?php print image_style_url($style, $file['#item']['uri']); ?>" alt="<?php print $row->field_data_field_slider_image_field_slider_image_alt; ?>" title="#caption-fid-<?php print $row->field_data_field_slider_image_field_slider_image_fid; ?>"/></a>

<?php endforeach;?>

问题是链接:$row->field_field_slider_link[0]['raw']['url']不是必需的游戏,因此不存在。

如何设置值,如果设置了值并打印备用行/如果没有则退出?

例如,如果没有链接值:

.   l($row->node_title, $row->field_field_slider_link[0]['raw']['url']) . '</h3></div><div class="body">' 

将是:

.   print $row->node_title . '</h3></div><div class="body">' 

. l(t('read more'), $row->field_field_slider_link[0]['raw']['url'], array('attributes' => array('class' => array('button_link'))));

根本不打印。

<a href="<?php print url($row->field_field_slider_link[0]['raw']['url']); ?>"><img src="<?php print image_style_url($style, $file['#item']['uri']); ?>" alt="<?php print $row->field_data_field_slider_image_field_slider_image_alt; ?>" title="#caption-fid-<?php print $row->field_data_field_slider_image_field_slider_image_fid; ?>"/></a>

将是:

<img src="<?php print image_style_url($style, $file['#item']['uri']); ?>" alt="<?php print $row->field_data_field_slider_image_field_slider_image_alt; ?>" title="#caption-fid-<?php print $row->field_data_field_slider_image_field_slider_image_fid; ?>"/>

非常感谢任何帮助。

由于

0 个答案:

没有答案