Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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_Arrays - Fatal编程技术网

Php 从数组中删除空值

Php 从数组中删除空值,php,arrays,Php,Arrays,我正在使用php函数创建一个带有分页的用户条目列表。我需要删除没有名字的条目,所以我尝试了这段代码,但它不起作用:没有名字的条目不会被删除 $listing->entries( $order, $eLimit, $eLimStart, true, array('owner' => $userid, 'name' != null), false, $section); 相反的方法效果很好,使用此代码,我可以获得所有没有名称的条目: $listing->entries( $ord

我正在使用php函数创建一个带有分页的用户条目列表。我需要删除没有名字的条目,所以我尝试了这段代码,但它不起作用:没有名字的条目不会被删除

$listing->entries( $order, $eLimit, $eLimStart, true, array('owner' => $userid, 'name' != null), false, $section);
相反的方法效果很好,使用此代码,我可以获得所有没有名称的条目:

$listing->entries( $order, $eLimit, $eLimStart, true, array('owner' => $userid, 'name' => null), false, $section);
在数据库中,名称如下所示:

- type: varchar(250)
- interclassement: utf8_general_ci
- Null: Yes
- Default: NULL
我使用的是PHP版本5.3.16

请问我做错了什么?非常感谢

***编辑*** 上下文:Joomla 2.5.9和SobiPro 1.08。我使用SobiPro API创建列表:

$listing = SPFactory::Controller('listing');
$listing = new SPListingCtrl();
函数条目如下所示

public function entries( $eOrder, $eLimit = null, $eLimStart = null, $count = false, $conditions = array(), $entriesRecursive = false, $pid = -1 )
{
    return $this->getEntries( $eOrder, $eLimit, $eLimStart, $count, $conditions, $entriesRecursive, $pid );
}
函数getEntries如下所示:

/**
 * @param string $eOrder
 * @param int $eLimit
 * @param int $eLimStart
 * @return array
 */
public function getEntries( $eOrder, $eLimit = null, $eLimStart = null, $count = false, $conditions = array(), $entriesRecursive = false, $pid = 0 )
{
    /* var SPDb $db */
    $db =& SPFactory::db();
    $eClass = SPLoader::loadModel( 'entry' );
    $entries = array();
    $eDir = 'asc';
    $oPrefix = null;
    $conditions = is_array( $conditions ) ? $conditions : array();

    /* get the ordering and the direction */
    if ( strstr( $eOrder, '.' ) ) {
        $eOr = explode( '.', $eOrder );
        $eOrder = array_shift( $eOr );
        $eDir = implode( '.', $eOr );
    }
    $pid = $pid ? $pid : SPRequest::sid();
    /* if sort by name, then sort by the name field */
    if ( $eOrder == 'name' ) {
        $eOrder = SPFactory::config()->nameField()->get( 'fid' );
    }
    if ( $entriesRecursive ) {
        $pids = $this->_model->getChilds( 'category', true );
        if ( is_array( $pids ) ) {
            $pids = array_keys( $pids );
        }
        $pids[ ] = SPRequest::sid();
        $conditions[ 'sprl.pid' ] = $pids;
    }
    else {
        $conditions[ 'sprl.pid' ] = $pid;
    }
    if ( $pid == -1 ) {
        unset( $conditions[ 'sprl.pid' ] );
    }

    /* sort by field */
    if ( strstr( $eOrder, 'field_' ) ) {
        static $field = null;
        $specificMethod = false;
        if ( !$field ) {
            try {
                $db->select( 'fieldType', 'spdb_field', array( 'nid' => $eOrder, 'section' => Sobi::Section() ) );
                $fType = $db->loadResult();
            }
            catch ( SPException $x ) {
                Sobi::Error( $this->name(), SPLang::e( 'CANNOT_DETERMINE_FIELD_TYPE', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
            }
            if ( $fType ) {
                $field = SPLoader::loadClass( 'opt.fields.' . $fType );
            }
        }
        if ( $field && method_exists( $field, 'sortBy' ) ) {
            $table = null;
            $oPrefix = null;
            $specificMethod = call_user_func_array( array( $field, 'sortBy' ), array( &$table, &$conditions, &$oPrefix, &$eOrder, &$eDir ) );
        }
        if ( !$specificMethod ) {
            $table = $db->join(
                array(
                    array( 'table' => 'spdb_field', 'as' => 'fdef', 'key' => 'fid' ),
                    array( 'table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid' ),
                    array( 'table' => 'spdb_object', 'as' => 'spo', 'key' => array( 'fdata.sid', 'spo.id' ) ),
                    array( 'table' => 'spdb_relations', 'as' => 'sprl', 'key' => array( 'fdata.sid', 'sprl.id' ) ),
                )
            );
            $oPrefix = 'spo.';
            $conditions[ 'spo.oType' ] = 'entry';
            $conditions[ 'fdef.nid' ] = $eOrder;
         //   $eOrder = 'baseData.' . $eDir;
         $eOrder = 'baseData = "", CONVERT(baseData,UNSIGNED INTEGER).' . $eDir;
        }
    }

    else {
        $table = $db->join( array(
            array( 'table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id' ),
            array( 'table' => 'spdb_object', 'as' => 'spo', 'key' => 'id' )
        ) );
        $conditions[ 'spo.oType' ] = 'entry';
        $eOrder = $eOrder . '.' . $eDir;
        $oPrefix = 'spo.';
        if ( strstr( $eOrder, 'valid' ) ) {
            $eOrder = $oPrefix . $eOrder;
        }
    }

    /* check user permissions for the visibility */
    if ( Sobi::My( 'id' ) ) {
        $this->userPermissionsQuery( $conditions, $oPrefix );
        if( isset( $conditions[ $oPrefix . 'state' ] ) && $conditions[ $oPrefix . 'state' ] ) {
            $conditions[ 'sprl.copy' ] = 0;
        }
    }
    else {
        $conditions = array_merge( $conditions, array( $oPrefix . 'state' => '1', '@VALID' => $db->valid( $oPrefix . 'validUntil', $oPrefix . 'validSince' ) ) );
        $conditions[ 'sprl.copy' ] = '0';
    }
    try {
        $db->select( $oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true );
        $results = $db->loadResultArray();
    }
    catch ( SPException $x ) {
        Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
    }
    Sobi::Trigger( $this->name(), 'AfterGetEntries', array( &$results, $count ) );
    if ( count( $results ) && !$count ) {
        $memLimit = ( int )ini_get( 'memory_limit' ) * 2097152;
        foreach ( $results as $i => $sid ) {
            // it needs too much memory moving the object creation to the view
            //$entries[ $i ] = SPFactory::Entry( $sid );
            $entries[ $i ] = $sid;
        }
    }
    if ( $count ) {
        return $results;
    }
    return $entries;
}

与其寻找非空条目,或许您可以做相反的事情,寻找包含以下内容的条目:

$listing->entries($order、$eLimit、$eLimStart、true、array('owner'=>$userid、'name'=>'%')、false、$section)


不过,这纯粹是猜测,因为我们需要查看
条目
函数来查看各种参数是如何处理的。

已解决-感谢大家的帮助


$listing->entries($order,$eLimit,$eLimStart,true,array('owner'=>$userid',!name'=>null),false,-1)

什么是
$listing->entries
函数?还有,
'name'!=null
将是
true
数组('owner'=>$userid,'name'!=null)
数组('owner'=>$userid,0=>true)相同。
数组('owner'=>$userid,'name'=>true)返回一个空数组,不显示带名称和不带名称的条目。数组('owner'=>$userid,0=>true)返回所有条目,即使没有名称。是否可以发布整个getEntries代码?当然可以,但它非常大!我已经更新了这个问题。谢谢大家的帮助。很有趣,但是没有名字的条目仍然会被返回。