[英]How To Set The value after Unset in php
我需要的
這是數組結構(未設置之前)
[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]);
//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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.