• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Return Array Elements that contain...

array (

[1] => 'uy87yh879sf s9d08fusdf 980dsf98 21/05/2006jidosfj89sd9 89uds9'

[2] => 'uy8/05/2006jidosfj89sd9 89uds9'

[3] => 'uy87yh879sf s9d08fusdf 980dsf98 21/089uds9'

[4] => 'uy87yh 21/05/2006jidosfj89sd9 89uds9'

[5] => '21/05/20069'

[6] => ' 21/05/2006jido'

 )

Returns 1,5,6

That is what I would like.

How would I go about accomplishing this?
0
mnb93
Asked:
mnb93
1 Solution
 
RoonaanCommented:
Hi,

I think array_filter is the best way to go:

You would define a filter function which says wether or not a certain element should be included or exclued from the resulting array:

function myFilter($data) {
  return strstr($data, '21/05/2006')
}

Then you call the array_filter function to get the filtered array:

$keys = array_keys(array_filter($array, 'myFilter'));

-r-
0
 
aminerdCommented:
Or...

$match = preg_grep('/21\/05\/2006/', $array);
var_dump($match);

If you want the keys, you can add:

$keys = array_keys($match);



http://php.net/preg_grep
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now