-2

我遇到了一些麻烦我有$currentPages存储以下数据的变量

Array ( [1] => CMS_Content_Item_Page Object ( [id] => 1 [name] => Soft Snacks [headline] => Soft Snacks [image] => /ImageUploaded/4page-img1.png [description] => Cheese Burger.................................................................3500 Frw Beef Burger.....................................................................3000 Frw Eggs Burger.....................................................................3500 Frw [content] => Cheese Burger.................................................................3500 Frw Beef Burger.....................................................................3000 Frw Eggs Burger.....................................................................3500 Frw Meat Ball ( 3 ) ................................................................1500 Frw Chicken wings.................................................................4000 Frw Sambusa ( 3 ).................................................................1500 Frw Cheese Plate ..................................................................2500 Frw Cheese Sausage..............................................................3500 Frw [parent_id] => 0 [_namespace:protected] => restaurant [_restaurantModel:protected] => Application_Model_Restaurant Object ( [_name:protected] => restaurants [_dependentTables:protected] => Array ( [0] => Application_Model_ContentNode ) [_referenceMap:protected] => Array ( [Restaurant] => Array ( [columns] => Array ( [0] => parent_id ) [refTableClass] => Application_Model_Restaurant [refColumns] => Array ( [0] => id ) [onDelete] => cascade [onUpdate] => restrict ) ) [_definition:protected] => [_definitionConfigName:protected] => [_db:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_numericDataTypes:protected] => Array ( [0] => 0 [1] => 1 [2] => 2 [INT] => 0 [INTEGER] => 0 [MEDIUMINT] => 0 [SMALLINT] => 0 [TINYINT] => 0 [BIGINT] => 1 [SERIAL] => 1 [DEC] => 2 [DECIMAL] => 2 [DOUBLE] => 2 [DOUBLE PRECISION] => 2 [FIXED] => 2 [FLOAT] => 2 ) [_defaultStmtClass:protected] => Zend_Db_Statement_Pdo [_config:protected] => Array ( [host] => localhost [username] => hotelrwanda [password] => password [dbname] => hotelrwanda_db [charset] => [persistent] => [options] => Array ( [caseFolding] => 0 [autoQuoteIdentifiers] => 1 [fetchMode] => 2 ) [driver_options] => Array ( ) ) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( ) [_enabled:protected] => [_filterElapsedSecs:protected] => [_filterTypes:protected] => ) [_defaultProfilerClass:protected] => Zend_Db_Profiler [_connection:protected] => PDO Object ( ) [_caseFolding:protected] => 0 [_autoQuoteIdentifiers:protected] => 1 [_allowSerialization:protected] => 1 [_autoReconnectOnUnserialize:protected] => ) [_schema:protected] => [_cols:protected] => Array ( [0] => id [1] => parent_id [2] => namespace [3] => name [4] => date_created ) [_primary:protected] => Array ( [1] => id ) [_identity:protected] => 1 [_sequence:protected] => 1 [_metadata:protected] => Array ( [id] => Array ( [SCHEMA_NAME] => [TABLE_NAME] => restaurants [COLUMN_NAME] => id [COLUMN_POSITION] => 1 [DATA_TYPE] => int [DEFAULT] => [NULLABLE] => [LENGTH] => [SCALE] => [PRECISION] => [UNSIGNED] => [PRIMARY] => 1 [PRIMARY_POSITION] => 1 [IDENTITY] => 1 ) [parent_id] => Array ( [SCHEMA_NAME] => [TABLE_NAME] => restaurants [COLUMN_NAME] => parent_id [COLUMN_POSITION] => 2 [DATA_TYPE] => int [DEFAULT] => [NULLABLE] => 1 [LENGTH] => [SCALE] => [PRECISION] => [UNSIGNED] => [PRIMARY] => [PRIMARY_POSITION] => [IDENTITY] => ) [namespace] => Array ( [SCHEMA_NAME] => [TABLE_NAME] => restaurants [COLUMN_NAME] => namespace [COLUMN_POSITION] => 3 [DATA_TYPE] => varchar [DEFAULT] => [NULLABLE] => 1 [LENGTH] => 50 [SCALE] => [PRECISION] => [UNSIGNED] => [PRIMARY] => [PRIMARY_POSITION] => [IDENTITY] => ) [name] => Array ( [SCHEMA_NAME] => [TABLE_NAME] => restaurants [COLUMN_NAME] => name [COLUMN_POSITION] => 4 [DATA_TYPE] => varchar [DEFAULT] => [NULLABLE] => 1 [LENGTH] => 100 [SCALE] => [PRECISION] => [UNSIGNED] => [PRIMARY] => [PRIMARY_POSITION] => [IDENTITY] => ) [date_created] => Array ( [SCHEMA_NAME] => [TABLE_NAME] => restaurants [COLUMN_NAME] => date_created [COLUMN_POSITION] => 5 [DATA_TYPE] => int [DEFAULT] => [NULLABLE] => 1 [LENGTH] => [SCALE] => [PRECISION] => [UNSIGNED] => [PRIMARY] => [PRIMARY_POSITION] => [IDENTITY] => ) ) [_metadataCache:protected] => [_metadataCacheInClass:protected] => 1 [_rowClass:protected] => Zend_Db_Table_Row [_rowsetClass:protected] => Zend_Db_Table_Rowset [_defaultSource:protected] => defaultNone [_defaultValues:protected] => Array ( ) ) ) ) 

在使用 array_shift 函数后,它只给了我 Array ( ) 这没什么,有没有其他选项可以帮助处理这些数据。

[编辑] 基本上,我在这里使用 zend 框架是处理这个 array() 的脚本

public function indexAction()
{
    $mdlPagepageModel = new Application_Model_Restaurant();
    $recentPages = $mdlPagepageModel->getRecentRestaurants();
    if (is_array($recentPages)) {
        // the 3 most recent items are the featured items
        for ($i = 1; $i <= 2; $i ++) {
            if (count($recentPages) > 0) {
                $featuredItems[] = array_shift($recentPages);
            }
        }
        $this->view->featuredItems = $featuredItems;

        if (count($recentPages) > 0) {

            $this->view->recentPages = $recentPages;
        } else {
            $this->view->recentPages = $null;
        }
    } else{
        throw new Zend_Exception("Currently, menu does't have any file!");
    }    
}
4

1 回答 1

1

那是因为整个数组是数组(对象)的第一个元素,使用 array_shift 删除它。你想做什么?

于 2012-04-25T15:49:00.050 回答