略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Yaconf::get

2024-11-12

Yaconf::get

(PECL yaconf >= 1.0.0)

Yaconf::getRetrieve a item

说明

public static Yaconf::get(string $name, mixed $default_value = NULL): mixed

参数

name

Configuration key, the key looks like "filename.key", or "filename.sectionName,key".

default_value

if the key doesn't exists, Yaconf::get will return this as result.

返回值

Returns configuration result(string or array) if the key exists, return default_value if not.

范例

示例 #1 INI()example

;filenmame foo.ini, placed in directory which is yaconf.directoy
[SectionA]
;key value pair
key=val
;hash[a]=val
hash.a=val
;arr[0]=val
arr.0=val
;or
arr[]=val

;SectionB inherits SectionA
[SectionB:SectionA]
;override configuration key in SectionA
key=new_val

以上例程的输出类似于:

php7 -r 'var_dump(Yaconf::get("foo.SectionA.key"));'
//string(3) "val"

php7 -r 'var_dump(Yaconf::get("foo.SectionB.key"));'
//string(7) "new_val"

php7 -r 'var_dump(Yaconf::get("foo")["SectionA"]["hash"]);'
//array(1)

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/yaconf.get.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3