Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [0] => Array
- (
- [0] => REPORTIDXXXXXXXXXXXXXXXXXXXXXXXXXXX
- [1] => REPORT EXPORT NAME#1
- [2] => REPORT DESCRIPTION #1
- [3] => 2012-10-02T17:31:30
- )
- [1] => Array
- (
- [0] => REPORTIDYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
- [1] => REPORTOTHERNAME#2
- [2] => REPORTDESCRIPTION #2
- [3] => 2012-09-28T15:15:17
- )
- [2] => Array
- (
- [0] => REPORTIDZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
- [1] => REPORT EXPORT NAME#3
- [2] => REPORT DESCRIPTION #3
- [3] => 2012-09-28T14:59:17
- )
- function get_report_ids(array $rs) {
- $results = array();
- // loop over your data structure
- foreach($rs as $key => $data) {
- // If element 1 contains EXPORT (case insensitive)
- if(stripos($data[1], 'EXPORT') !== false) {
- // regex to capture the ID from element 0
- if(preg_match('/^EXPORTID(.*)$/i', $data[0], $matches)) {
- // add the ID to the results array
- $results[] = $matches[1];
- }
- }
- }
- // if we had results then return the array, otherwise return null
- return !empty($results) ? $results : null;
- }
- array(
- 0 => 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
- 1 => 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
- )
- $array = array(
- 0 => array(0 => "REPORTIDXXXXXXXXXXXXXXXXXXXXXXXXXXX",1 => "REPORT EXPORT NAME#1",2 => "REPORT DESCRIPTION #1",3 => "2012-10-02T17:31:30"),
- 1 => array(0 => "REPORTIDYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",1 => "REPORTOTHERNAME#2",2 => "REPORTDESCRIPTION #2",3 => "2012-09-28T15:15:17"),
- 2 => array(0 => "REPORTIDZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",1 => "REPORT EXPORT NAME#3",2 => "REPORT DESCRIPTION #3",3 => "2012-09-28T14:59:17")
- );
- $array = array_map(function ($var) {
- preg_match('/^REPORTID(w+)/i', $var[0], $result);
- return $result[1];
- }, $array);
- var_dump($array);
- array
- 0 => string 'XXXXXXXXXXXXXXXXXXXXXXXXXXX' (length=27)
- 1 => string 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYY' (length=29)
- 2 => string 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ' (length=28)
Add Comment
Please, Sign In to add comment