If I have two strings in an array:
$x = array("int(100)", "float(2.1)");
is there a simple way of reading each value as the number stored inside as a number?
The reason is I am looking at a function (not mine) that sometimes receives an int and sometimes a float. I cannot control the data it receives.
function convertAlpha($AlphaValue) {
return((127/100)*(100-$AlphaValue));
}
It causes an error in php
PHP Notice: A non well formed numeric value encountered
which I want to get rid of.
I could strip the string down and see what it is and do an intval/floatval but wondered if there was a neat way.
UPDATE:
Playing about a bit I have this:
function convertAlpha($AlphaValue) {
$x = explode("(", $AlphaValue);
$y = explode(")", $x[1]);
if ($x[0] == "int") {
$z = intval($y[0]);
}
if ($x[0] == "float") {
$z = floatval($y[0]);
}
return((127/100)*(100-$z)); }
This which works but it just messy.