0

I am search the year 2018 from $data array. It will return the value Jan.

I need to display Jan 2018

Sample Code

$data = Array(
    '2017-08' => 'Aug 2017',
    '2017-09' => 'Sep 2017',
    '2017-10' => 'Oct 2017',
    '2017-11' => 'Nov 2017',
    '2017-12' => 'Dec 2017',
    '2018-01' => 'Jan 2018'
);
$input = preg_quote('2018', '~');
$result = preg_filter('~' . $input . '~', false, $data);
print_r($result);

Auctual Output

Array
(
    [2018-01] => Jan 
)

Expected Output

Array
(
    [2018-01] => Jan 2018
)

Please Advise!

1
  • By the way, your example is for $input = preg_quote('2018', '~');, not $input = preg_quote('2017', '~'); as you quoted. Commented Feb 23, 2018 at 10:53

1 Answer 1

2

preg_filter works as a search and replace function, so you're simply replacing the found "2018" with nothing. Maybe you were more looking for something like preg-grep?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.