format Posted December 18, 2015 Share Posted December 18, 2015 Hi All, I am using the below with great success. It finds for me the MIn and max values allong with the company names. The problem that has just presented itself is some of the data returned in the SLevel is text. I need to ignore text and only include numeric values. Is this possible. I have tried to work this out but have hit a brick wall. Many thanks Jon $SLevels = array();foreach ($xml->Type->Company as $item){ $companyName = (string) $item->Name; // get the company name $tmp = (array) $item->$Level; if($tmp[0] != '-') $SLevels[] = array($tmp[0], $companyName); // add SLevel and company name to array}$minSLevel = min($SLevels); // get minimum value$minSLevel[0] = str_replace(',', '', $minSLevel[0]);$premium = $minSLevel[0];$company = $minSLevel[1]; $maxSLevel = max($SLevels); // get minimum value$maxSLevel[0] = str_replace(',', '', $maxSLevel[0]);$maxpremium = $maxSLevel[0];$maxcompany = $maxSLevel[1]; Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted December 19, 2015 Solution Share Posted December 19, 2015 Seems weird that you have this mixture of numbers and strings, but whatever. So you only want to add to $SLevels if the data is a number? I figure if($tmp[0] != '-')would be a good place to do that. To test for a number, try is_numeric. Quote Link to comment Share on other sites More sharing options...
format Posted December 19, 2015 Author Share Posted December 19, 2015 Thanks for reply, ya Im not in control of the data. Its coming from a live quote system and they replace what should be a numberwith a text message for any companies that dont return a quote. I tired the below but I think the problem here is I just dont understand how it should work.. I can use is_numeric and even concidered strpos but no joy. Im trying to only add to the array numbers. if(is_numeric($tmp[0])) $maxLevels[] = $tmp[0]; Quote Link to comment Share on other sites More sharing options...
format Posted December 20, 2015 Author Share Posted December 20, 2015 if(is_numeric($tmp2[0]))// ignore non number $maxLevels[] = $tmp2[0]; // add JLevel to array Thanks requinix. I have it working. I had a typo which. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.