Php 从文本数组中提取数值
如何从该数组中提取数值Php 从文本数组中提取数值,php,arrays,string,int,Php,Arrays,String,Int,如何从该数组中提取数值 array ( 0 => '\'268', 1 => '252',) 只需要把数字去掉,然后我需要做一些计算 $source = array( 0 => '\'268', 1 => '252', ); function strip($element) { $matches = array(); preg_match('#[0-9]+#', $element, $matches); return (
array (
0 => '\'268',
1 => '252',)
只需要把数字去掉,然后我需要做一些计算
$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);
结果:
array (size=2)
0 => int 268
1 => int 252
您期望的输出是什么???两个字符串或两个整数,但只有数字,没有特殊字符。谢谢。我用了漫长而艰难的方式,但这看起来容易多了:)。我使用了$tcx=(int)(trim($tc2[0],“\”);$tcy=(int)(trim($tc2[1],“”));这会返回两个字符串。我假设我不需要在结束代码中执行var\u转储($result)?