ridzhi/smarrt

智能数组访问

此包的官方仓库似乎已丢失,因此该包已被冻结。

2.0.0 2016-08-08 13:57 UTC

This package is not auto-updated.

Last update: 2023-06-10 12:28:33 UTC


README

点表示法访问API

点实现了ArrayAccess接口。

$arr = [
	...
];

$dot = new Dot($arr);

设置

// assoc arrays
$dot['node1.node2'] = 'value';

// also you can use dot with indexed array
$dot['node1.node2.0.1'] = 'value'; //equal $dot['node1']['node2'][0][1] = 'value'

// if key is not exists, it will be created
$dot['node1.not_exists_key'] = 'value';

获取

// equal $email = $dot['feedbacks'][0]['email']
// if key is not exists, return null
$email = $dot['feedbacks.0.email'];

未设置/已设置/为空

unset($dot['node1.node2'])
isset($dot['node1.node2'])
empty($dot['node1.node2'])