3

我有以下变量:

$something = 'whatever';
$hello = array();
$test = 123;

我想将它们推入这样的数组中:

$data['something'] = 'whatever';
$data['hello'] = array();
$data['test'] = 123;

我想知道是否有某种 PHP 函数(类似于array_push())可以将变量推入数组,使用变量的名称作为键值?

4

1 回答 1

6

就在这里。compact()会做到这一点。

于 2012-09-11T19:34:19.047 回答