0

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!

1
  • Are you saying that the array contains values that is alphanumeric and that you have a string of text followed by numbers? Do you know the length of either the string of text or the number of digits in the number? Commented Apr 9, 2011 at 2:56

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for using a callback and not writing the 12873523rd for loop in PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.