这是我的PHP代码:
forms.py
输出是:
<?php
$stack = array( 0 => array("orange", "banana", "apple", "raspberry"),1 => array("banana", "apple", "raspberry"),2 => array("apple", "raspberry"),'a' => array("raspberry"));
$temp = array_keys($stack);
array_shift($temp);
foreach($temp as $item){
$dd[$item] = $stack[$item];
}
print_r($dd);
?>
但循环通过I打印数组时缺少第一个元素。它应该是最后的数组列表.....
答案 0 :(得分:0)
检查此代码它将移动第一个数组并在数组的最后添加而不重置数组键:
我希望这对你有用......
<?php
$stack = array( 0 => array("orange", "banana", "apple", "raspberry"),1 => array("banana", "apple", "raspberry"),2 => array("apple", "raspberry"),'a' => array("raspberry"));
$temp = array_keys($stack);
$tem = array_shift($temp);
$temp[] = $tem;
$dd = array();
foreach($temp as $item){
$dd[$item] = $stack[$item];
}
echo"<pre>"; print_r($dd);
?>
输出:
阵列( [1] =&gt;排列 ( [0] =&gt;香蕉 [1] =&gt;苹果 [2] =&gt;覆盆子 )
[2] => Array ( [0] => apple [1] => raspberry ) [a] => Array ( [0] => raspberry ) [0] => Array ( [0] => orange [1] => banana [2] => apple [3] => raspberry )
)
答案 1 :(得分:-1)
如果您只想获取数组中第一个元素的值(不删除它),请使用reset($stack)
。
array_shift()
将从数组中删除元素并返回值。