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

我需要帮助从该对象中随机挑选一个项目并显示它。

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 回答