2

次のようなiniファイルがあります。

[hints]
menu.0 = "Hint: Dropping a element on parent element will move the selected element at the end of list!"
menu.1 = "Hint: Use Menu elements to beautify your navigator!"
menu.2 = "Hint: Pages in red means they are draft pages. Adding them to your menu means that your visitors can not see the page!"

Zend_Config_Ini を使用して ini ファイルを読み取ります。

self::$hints = new Zend_Config_Ini(APPLICATION_PATH . '/configs/hints.ini',
                                      'hints');

出力var_dump(self::$hints->menu);は次のとおりです。

object(Zend_Config)[63]
  protected '_allowModifications' => boolean false
  protected '_index' => int 0
  protected '_count' => int 3
  protected '_data' => 
    array (size=3)
      0 => string 'Hint: Dropping a element on parent element will move the selected element at the end of list!' (length=93)
      1 => string 'Hint: Use Menu elements to beautify your navigator!' (length=51)
      2 => string 'Hint: Pages in red means they are draft pages. Adding them to your menu means that your visitors can not see the page!' (length=118)
  protected '_skipNextIteration' => null
  protected '_loadedSection' => null
  protected '_extends' => 
    array (size=0)
      empty
  protected '_loadFileErrorStr' => null

そのオブジェクトから 1 つのアイテムをランダムに選択して表示する方法について助けが必要です。

4

1 に答える 1

3

この PHP 関数は次の場合に役立ちます。

array_rand();

参考:PHP.netのarray_rand()

オブジェクトであるため、以前に次のことができます。

$arr = (array)$object;

https://stackoverflow.com/a/1897695/2228023で提案されているように

于 2013-03-31T19:16:03.530 に答える