Guest User

Untitled

a guest
Jan 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. [0] => Array
  2. (
  3. [0] => REPORTIDXXXXXXXXXXXXXXXXXXXXXXXXXXX
  4. [1] => REPORT EXPORT NAME#1
  5. [2] => REPORT DESCRIPTION #1
  6. [3] => 2012-10-02T17:31:30
  7. )
  8.  
  9. [1] => Array
  10. (
  11. [0] => REPORTIDYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
  12. [1] => REPORTOTHERNAME#2
  13. [2] => REPORTDESCRIPTION #2
  14. [3] => 2012-09-28T15:15:17
  15. )
  16.  
  17. [2] => Array
  18. (
  19. [0] => REPORTIDZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
  20. [1] => REPORT EXPORT NAME#3
  21. [2] => REPORT DESCRIPTION #3
  22. [3] => 2012-09-28T14:59:17
  23. )
  24.  
  25. function get_report_ids(array $rs) {
  26. $results = array();
  27. // loop over your data structure
  28. foreach($rs as $key => $data) {
  29.  
  30. // If element 1 contains EXPORT (case insensitive)
  31. if(stripos($data[1], 'EXPORT') !== false) {
  32. // regex to capture the ID from element 0
  33. if(preg_match('/^EXPORTID(.*)$/i', $data[0], $matches)) {
  34. // add the ID to the results array
  35. $results[] = $matches[1];
  36. }
  37. }
  38. }
  39.  
  40. // if we had results then return the array, otherwise return null
  41. return !empty($results) ? $results : null;
  42. }
  43.  
  44. array(
  45. 0 => 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
  46. 1 => 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
  47. )
  48.  
  49. $array = array(
  50. 0 => array(0 => "REPORTIDXXXXXXXXXXXXXXXXXXXXXXXXXXX",1 => "REPORT EXPORT NAME#1",2 => "REPORT DESCRIPTION #1",3 => "2012-10-02T17:31:30"),
  51. 1 => array(0 => "REPORTIDYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",1 => "REPORTOTHERNAME#2",2 => "REPORTDESCRIPTION #2",3 => "2012-09-28T15:15:17"),
  52. 2 => array(0 => "REPORTIDZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",1 => "REPORT EXPORT NAME#3",2 => "REPORT DESCRIPTION #3",3 => "2012-09-28T14:59:17")
  53. );
  54.  
  55. $array = array_map(function ($var) {
  56. preg_match('/^REPORTID(w+)/i', $var[0], $result);
  57. return $result[1];
  58. }, $array);
  59.  
  60. var_dump($array);
  61.  
  62. array
  63. 0 => string 'XXXXXXXXXXXXXXXXXXXXXXXXXXX' (length=27)
  64. 1 => string 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYY' (length=29)
  65. 2 => string 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ' (length=28)
Add Comment
Please, Sign In to add comment