2012-04-25 13 views
-2

では正常に動作していない私は、データ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機能を使用した後、何もないもの)(私だけアレイを与えているの下に保存$currentPages変数を持っているいくつかの問題を抱えています、そこにありますこのデータを処理するのに役立つその他のオプション。

アレイ全体、アレイ(オブジェクト)の最初の要素であるからである[EDIT]基本的に、私はここで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

なぜすべてが1行にあるのですか?どのように地球をデバッグするつもりですか?それとも私たちがそうすることをどのように期待していますか? – GolezTrol

+0

データベース名、dbユーザー名、およびパスワードを投稿したばかりなので、これがローカルホストの展開であることを本当に願っています。 [username] => hotelrwanda [password] =>パスワード[dbname] => hotelrwanda_db – Kzqai

+0

haha​​ha、はいこれは単なる例です – Akrambek

答えて

1

array_shiftを使用して削除します。あなたは何をしようとしているのですか?

+0

多分私は彼の間違ったダンプを読んでいる..しかし 'array_shift(array(1 => $ obj)))' '$ obj'を返します。 –

+0

彼が与えたダンプでは、配列の最初のオブジェクトが唯一のオブジェクトであり、他はすべてその最初のキーの下にあります(コードエディタにポストされています)。彼が与えたダンプのarray_shiftを使うと、それは単に全体を削除するだけです。 – squarephoenix

+0

ああ、私はAkramが元の配列ではなく、 'array_shift()'の結果をダンプしていると仮定しました。 –