我需要什么
- i首先取消设置数组值后,需要保留这些值
以下是阵列结构(未设置之前)
[0] => Array
(
[currency] => INR
)
[1] => Array
(
[type] => General Public Tickets Adult
[amount] => 50
[comment] => (Working Days)
)
[2] => Array
(
[type] => General Public Tickets Adult
[amount] => 80
[comment] => (Saturday/ Sunday/ Holiday)
)
以下是阵列结构(取消设置后)
[1] => Array
(
[type] => General Public Tickets Adult
[amount] => 50
[comment] => (Working Days)
)
[2] => Array
(
[type] => General Public Tickets Adult
[amount] => 80
[comment] => (Saturday/ Sunday/ Holiday)
)
这是php代码
unset($data[0]);
/* code to set the value after unset */
$data= array_values($data[0]);
- i需要将货币放入另一个数组
- 首先,我从数组中取消设置数组值[货币]
- 然后我想把[货币]放在另一个数组中
- 从数组中取消设置后,如何设置值
//save element to a new variable
$temp = $data[0];
//unset element
unset($data[0]);
/* code to set the value after unset */
//add element back to the array
$data[0] = $temp;
OR
//To add elements to the beginning of an array, use array_unshift
array_unshift($data,$temp);
在新数组中取消设置货币值之前,需要先获取货币值。如果您取消设置,然后尝试访问它,则会导致未定义
尝试如下:
$arrNew = $data[0]; //save it new array
unset($data[0]); //unset it now