The following code automagically finds the highest price on a page:
$vw_link = get_field('shop_link');
$ch = curl_init($vw_link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cl = curl_exec($ch);
$dom = new DOMDocument();
@$dom->loadHTML($cl);
$xpath = new DOMXpath($dom);
$price = $xpath->query("//span[@class='price']");
foreach($price as $value) {
$vw_array[] = floatval(str_replace('$', '', $value->nodeValue));
update_field('shop_price',max($vw_array));
}
What would be the best thing since sliced cheese is if it could return the value in $vw_array that is between a specific amount, ie, greater than 100 and less than 200. The tricky part would be returning the first greatest number after 100, if there are multiple numbers between 100-200.
For example (if the following prices are all wrapped in 'price' class):
$88
$92
$105 <-- return this number
$125
$180
$210
Does anyone know how to conjure up such a magnificent function?