当前位置: 动力学知识库 > 问答 > 编程问答 >

PHP ARRAY - remove certain array value

问题描述:

Is there any function or method to remove array value for example, i have an array like this:

Array (

[0] => (Some string value)51351

[1] => (Some string value)43822

)

So the question is, How do i get the value that is not in the "( )". and counting the value of array after remove "( Some string value )" to do some looping process?

Thank you!

网友答案:
<?php

function digits_only($str){
 return preg_replace("/\(.*\)/", "", $str);
}

$arr = array("(Some content)531", "(Another Content)613");


$digits_array = array_map("digits_only", $arr);

var_dump($digits_array);

echo array_sum($digits_array);

Live Demo:

http://codepad.org/mYPL3PYH

分享给朋友:
您可能感兴趣的文章:
随机阅读: