array search
Moderator: General Moderators
array search
hi, can someone please help me out with an array search function that would find any number surrounded with a "^" before and after?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I usually don't do this, so consider yourself lucky
How I would do it
A more simple version would be to use a foreach(), and preg_match using the above pattern and place $matches[1] into a new array of numbers.
//outputs: Array ( [0] => 3423432 [1] => 432423 [2] => 342342 )
Code: Select all
$stack = array('test string ^3423432^', '^432423^ test string', 'dfdsffdsfd ^342342^');
$found = array_map(create_function('$stack', 'preg_match("#\^([0-9]+)\^#", $stack, $matches); return $matches[1];'), $stack);//outputs: Array ( [0] => 3423432 [1] => 432423 [2] => 342342 )