Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义索引-如何正确设置?_Php - Fatal编程技术网

Php 未定义索引-如何正确设置?

Php 未定义索引-如何正确设置?,php,Php,具有此功能,成员电子邮件回送返回未定义的索引。我该如何正确地设置它 function team_custom_columns( $column ) { global $post; switch ( $column ) { case 'member_email': $custom = get_post_custom(); echo $custom['member_email_address'][0];

具有此功能,成员电子邮件回送返回未定义的索引。我该如何正确地设置它

function team_custom_columns( $column ) {
    global $post;
    switch ( $column )
    {

        case 'member_email':
            $custom = get_post_custom();
            echo $custom['member_email_address'][0];
            break;
        case 'member_description':
            the_content();
            break;
    }
}

使用三元运算符:

echo isset($custom['member_email_address'][0])
     ? $custom['member_email_address'][0]
     : 'not set';
或者如果:

if (isset($custom['member_email_address'][0])) {
    // value exists
} else {
    // not set
}
你可以用!echo自定义post索引之前的empty()方法

function team_custom_columns( $column ) {
    global $post;
    switch ( $column )
    {

        case 'member_email':
            $custom = get_post_custom();
            if(!empty($custom['member_email_address'][0]))
                echo $custom['member_email_address'][0];
            break;
        case 'member_description':
            the_content();
            break;
    }
}

谢谢各位。这两个答案都很好,效果也很好。