oldmanriver — 2011-12-13T13:17:35-05:00 — #1
Found this old thread at:
Tinkered with it enough to know the REGEX part does not work, but gives "Array to string" conversion errors.
Anyway I need to do this on arrays where the value is 3 to 4 levels deep and the key must be accurate, so nesting and/or recalling of the function is necessary if the array value from "foreach ($myarray as $key => $value) is itself an array.
My search must work for searching substrings of the values similar to the SQL ==> field LIKE '%value%' <==.
In particular, I need to find today's date in a datetime field that MySQL has put into an array.
I need the Keys for this and or each occurance so I can accurately pull the data I need to push into another array being written to and Excel report.
All help appreciated!
cups — 2011-12-13T15:14:57-05:00 — #2
Are you asking this because you cannot influence Mysql to select matching dates in the database?
If you are then you might want to show us the sql statements which are generating these arrays.
If you are not, then you could show some example arrays - exact examples of what you have got - and what you want to end up with (obfuscate or remove anything which might be commercially valuable or too revealing of course).
oldmanriver — 2011-12-14T16:24:16-05:00 — #3
No control over the MySQL, just get this dump and have to massage it.
system — 2011-12-15T01:30:20-05:00 — #4
This can be accomplished by two ways:
- Using regular expressions (preg_grep). like
$lines = array('I have a cat.', 'My dog is blue.', 'One cute hamster.', 'Dogs are cool');
$matches = preg_grep('/\bdogs?\b/i', $lines);
$keys = array_keys($matches);
- Using foreach with its key/value pair followed by the string method stripos. Like
$my_array = array('one' => 'I have a cat.', 'two' => 'My dog is blue.', 'three' => 'One cute hamster.');
$search_term = "dog";
function search_array ( array $array, $term )
foreach ( $array as $key => $value )
if ( stripos( $value, $term ) !== false )