如何映射一个键到另一个对象数组


How to map one key to another in Object Array?

比如说,我有一个数组对象:

stdClass Object
(
    [uri] => sites/all/themes/bootstrap/templates/test-example.tpl.php
    [filename] => test-example.tpl.php
    [name] => test-example.tpl
)

是否有办法将[uri]映射到[filename] ?

的例子:

Array(
[sites/all/themes/bootstrap/templates/test-example.tpl.php] = [test-example.tpl.php]
) 

假设您的对象命名为$obj:

$map = array( $obj->uri => $obj->filename );
var_dump( $map );

如果您需要遍历许多元素,您可以使用foreach,但逻辑是相同的。