2012-04-25 92 views
-2

正常工作,我有一些麻煩,我有$currentPages變量,它存儲以下數據array_shift功能沒有在PHP

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這是什麼功能它給我只是陣列(),有任何其他可以幫助處理這些數據的選項。

[編輯]基本上,我使用這裏Zend框架是處理這一陣列()

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!"); 
    }  
} 
+1

爲什麼一切都在一條線上?你到底要如何調試?或者你如何期待我們這樣做? – GolezTrol 2012-04-25 15:50:08

+0

我真的希望這是一個localhost部署,因爲你剛剛發佈了你的數據庫名稱,數據庫用戶名和密碼。 [用戶名] =>盧旺達飯店[密碼] =>密碼[DBNAME] => hotelrwanda_db – Kzqai 2012-04-25 15:54:35

+0

哈哈,是的,這僅僅是例子, – Akrambek 2012-04-25 15:56:52

回答

1

,這是因爲整個陣列是陣列的第一個元素(對象)的腳本,使用array_shift正在刪除它。你想做什麼?

+0

也許我正在讀他的轉儲錯誤..但'array_shift(array(1 => $ obj)));'返回'$ obj'。 – 2012-04-25 15:54:29

+0

在他給出的轉儲(發佈到代碼編輯器中)中,數組的第一個對象是唯一的對象,其他所有對象都在該第一個鍵之下。如果他使用他給出的轉儲的array_shift,它會刪除整個東西。 – squarephoenix 2012-04-25 16:04:03

+0

Ahhh,我假定Akram傾倒'array_shift()'的結果,而不是原始數組。 – 2012-04-25 16:06:16