softboxkid
softboxkid

Reputation: 908

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!

Upvotes: 0

Views: 732

Answers (1)

Mike Lewis
Mike Lewis

Reputation: 64147

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

Upvotes: 2

Related Questions