Reputation: 133
How do I extract the numeric values from this array?
array (
0 => '\'268',
1 => '252',)
Just need the numbers stripped out, then I need to do some calculations.
Upvotes: 0
Views: 72
Reputation: 3088
$source = array(
0 => '\'268',
1 => '252',
);
function strip($element)
{
$matches = array();
preg_match('#[0-9]+#', $element, $matches);
return (int)reset($matches);
}
$result = array_map('strip', $source);
var_dump($result);
with result:
array (size=2)
0 => int 268
1 => int 252
Upvotes: 1