Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从文本数组中提取数值_Php_Arrays_String_Int - Fatal编程技术网

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)?