-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpQuestions.php
46 lines (33 loc) · 1.05 KB
/
phpQuestions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class PHPQuestions
{
// xml data to more readable json
function xmlToJson( $xmlLink )
{
$resp = simplexml_load_file( $xmlLink );
return json_encode($resp);
}
// return list having more than a provided price
function filterItemWithPrice( $thresHoldPrice )
{
$ids = [ 1, 2, 3 ];
$prices = [ 200 , 500 , 100 ];
$resp = ['item' => "", 'sumTotal' => ""];
$filteredIDS = [];
$filteredPriceArray = [];
foreach( $prices as $key => $price ):
if( $price > $thresHoldPrice ):
array_push( $filteredIDS, $ids[$key] );
array_push( $filteredPriceArray, $price );
endif;
endforeach;
$resp['item'] = $filteredIDS;
$resp['sumTotal'] = $this->totalSumofPrices( $filteredPriceArray );
return (object) $resp;
}
// total sum of prices from list
function totalSumofPrices( $filteredPriceArray )
{
return array_sum($filteredPriceArray);
}
}