I've a following Multidimensional array named $data
$data =
Array
(
[0] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] =>
[SubRegion] =>
[Country] =>
[typeofrec] => 0
[TotalAllocations] => 1000
[TotalTransfersOut] => 0
[TotalTransfersIn] => 0
[StartOfAllocation] => 1000
[ApprovedActivities] => 0
[AvailableBalance] => 1000
[TotalApprovedClaims] => 0
[Balance] => 1000
[TotalUnApprovedClaims] => 0
[Exposure] => 1000
)
[1] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] =>
[SubRegion] =>
[Country] =>
[typeofrec] => 0
[TotalAllocations] => 0
[TotalTransfersOut] => 0
[TotalTransfersIn] => 50
[StartOfAllocation] => 50
[ApprovedActivities] => 0
[AvailableBalance] => 50
[TotalApprovedClaims] => 0
[Balance] => 50
[TotalUnApprovedClaims] => 0
[Exposure] => 50
)
[2] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] => EMEA
[SubRegion] =>
[Country] =>
[typeofrec] => 0
[TotalAllocations] => 0
[TotalTransfersOut] => 0
[TotalTransfersIn] => 25
[StartOfAllocation] => 25
[ApprovedActivities] => 0
[AvailableBalance] => 25
[TotalApprovedClaims] => 0
[Balance] => 25
[TotalUnApprovedClaims] => 0
[Exposure] => 25
)
[3] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] => APJeC
[SubRegion] => India
[Country] => India
[typeofrec] => 0
[TotalAllocations] => 500
[TotalTransfersOut] => 0
[TotalTransfersIn] => 0
[StartOfAllocation] => 500
[ApprovedActivities] => 0
[AvailableBalance] => 500
[TotalApprovedClaims] => 0
[Balance] => 500
[TotalUnApprovedClaims] => 0
[Exposure] => 500
)
)
and
$amount =10;
$index = 2 // selected array index for change
The above information i have and i need to update the array with new [AvailableBalance] based on below calculations.
Next i need to get the [AvailableBalance] from the array $index (index 2 )
$existing_available = 25;
Subtract the $amount from $existing_availablet
$remaining_amount = 15; // where ($existing_available - $amount)
Update the [AvailableBalance] = 15($remaining_amount) using array $index (index2).
so my final array look like below:
$data =
Array
(
[0] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] =>
[SubRegion] =>
[Country] =>
[typeofrec] => 0
[TotalAllocations] => 1000
[TotalTransfersOut] => 0
[TotalTransfersIn] => 0
[StartOfAllocation] => 1000
[ApprovedActivities] => 0
[AvailableBalance] => 1000
[TotalApprovedClaims] => 0
[Balance] => 1000
[TotalUnApprovedClaims] => 0
[Exposure] => 1000
)
[1] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] =>
[SubRegion] =>
[Country] =>
[typeofrec] => 0
[TotalAllocations] => 0
[TotalTransfersOut] => 0
[TotalTransfersIn] => 50
[StartOfAllocation] => 50
[ApprovedActivities] => 0
[AvailableBalance] => 50
[TotalApprovedClaims] => 0
[Balance] => 50
[TotalUnApprovedClaims] => 0
[Exposure] => 50
)
[2] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] => EMEA
[SubRegion] =>
[Country] =>
[typeofrec] => 0
[TotalAllocations] => 0
[TotalTransfersOut] => 0
[TotalTransfersIn] => 25
[StartOfAllocation] => 25
[ApprovedActivities] => 0
[AvailableBalance] => 15 // updated value
[TotalApprovedClaims] => 0
[Balance] => 25
[TotalUnApprovedClaims] => 0
[Exposure] => 25
)
[3] => Array
(
[AllocationPool] => TEST do not USE
[Quarter] => 2016-Q4
[Region] => APJeC
[SubRegion] => India
[Country] => India
[typeofrec] => 0
[TotalAllocations] => 500
[TotalTransfersOut] => 0
[TotalTransfersIn] => 0
[StartOfAllocation] => 500
[ApprovedActivities] => 0
[AvailableBalance] => 500
[TotalApprovedClaims] => 0
[Balance] => 500
[TotalUnApprovedClaims] => 0
[Exposure] => 500
)
)
Please help me to try this issue.
I am new in php and stack overflow.
Thanks in advance..