我有一个像这样的数组
Array
(
[0] => Array
(
[s_id] => 4
[si_id] => sec_1
[d_id] => dep_4
[s_name] => sec1
[s_location] => LA
[s_visibility] => yes
[s_created_date] => 1273639343
[s_last_updated_date] => 1273639343
[s_created_by] => someone
[s_last_updated_by] => everyone
)
)
现在我想将数组[0]提取到数组中...意味着我想要这个
Array
(
[s_id] => 4
[si_id] => sec_1
[d_id] => dep_4
[s_name] => sec1
[s_location] => LA
[s_visibility] => yes
[s_created_date] => 1273639343
[s_last_updated_date] => 1273639343
[s_created_by] => someone
[s_last_updated_by] => everyone
)
我如何获得以上结果?
答案 0 :(得分:5)
你可以这样做:
$newArray = $oldArray[0];
这将创建一个具有相同键值对的 new 数组。
如果您不想创建新阵列并希望新阵列引用到$oldArray
中的现有阵列,您可以这样做:
$newArray = &$oldArray[0];
在这种情况下,对$newArray
所做的任何更改也会更改$oldArray
。
答案 1 :(得分:0)
看到它可能对你有用,
$sss = array () ;
$sss['sadness']['info'] = "some info";
$sss['sadness']['info2'] = "more info";
$sss['sadness']['value'] = "value";
$sss['happiness']['info'] = "some info";
$sss['happiness']['info2'] = "more info";
$sss['happiness']['value'] = "value";
$sss['peace']['info'] = "some info";
$sss['peace']['info2'] = "more info";
$sss['peace']['value'] = "value";
print_r($sss['sadness']);
echo "<br>";
print_r($sss);
echo "<br>";
输出1:
Array ( [info] => some info [info2] => more info [value] => value )
输出2:
Array ( [sadness] => Array ( [info] => some info [info2] => more info [value] => value ) [happiness] => Array ( [info] => some info [info2] => more info [value] => value ) [peace] => Array ( [info] => some info [info2] => more info [value] => value ) )