I cannot seem to find the correct way to access the VAT value of this array…
$freeholdPurchases = array( 'up to £150,000' => array('costs' => '£620.83', 'VAT' => '£124.17' , 'Total' => '£745.00'), '£150,000 - £200,000' => array('costs' => '£620.83', 'VAT' => '£124.17', 'Total' => '£745.00'), '£200,001 - £250,000' => array('costs' => '£700.00', 'VAT' => '£140.00', 'Total' => '£840.00'), '£250,001 - £300,000' => array('costs' => '£741.67', 'VAT' => '£148.33', 'Total' => '£890.00'), '£300,001 - £400,000' => array('costs' => '£783.33', 'VAT' => '£156.67', 'Total' => '£940.00'), '£400,001 - £500,000' => array('costs' => '£825.00', 'VAT' => '£165.00', 'Total' => '£990.00'), '£500,001 - £600,000' => array('costs' => '£866.67', 'VAT' => '£173.33', 'Total' => '£1,040.00'), '£600,001 to £700,000' => array('costs' => '£908.33', 'VAT' => '£181.67', 'Total' => '£1,090.00'), '£700,001 - £800,000' => array('costs' => '£950.00', 'VAT' => '£190.00', 'Total' => '£1,140.00'), '£800,001 - £900,000' => array('costs' => '£991.67', 'VAT' => '£198.33', 'Total' => '£1,190.00'), '£900,001 to £1,000,000' => array('costs' => '£1,033.33', 'VAT' => '£206.67', 'Total' => '£1,240.00') );
In my limited knowledge i’ve tried:
$freeholdPurchases['up to £150,000'][1][0]
and lots of variations of this but cant seem to figure it out
can anyone help me understand the syntax i need to access it or if i need to change my array at all.
Thanks
Advertisement
Answer
The question was to access the VAT value of this array. You will get VAT with the value of £ 148.33 with
$vat148p33 = $freeholdPurchases['£250,001 - £300,000']['VAT'];
All values and the area:
foreach($freeholdPurchases as $area => $row){ echo 'Area: '.$area.' VAT:'.$row['VAT'].'<br>'; }
Output:
Area: up to £150,000 VAT:£124.17 Area: £150,000 - £200,000 VAT:£124.17 Area: £200,001 - £250,000 VAT:£140.00 Area: £250,001 - £300,000 VAT:£148.33 Area: £300,001 - £400,000 VAT:£156.67 Area: £400,001 - £500,000 VAT:£165.00 Area: £500,001 - £600,000 VAT:£173.33 Area: £600,001 to £700,000 VAT:£181.67 Area: £700,001 - £800,000 VAT:£190.00 Area: £800,001 - £900,000 VAT:£198.33 Area: £900,001 to £1,000,000 VAT:£206.67