I am trying to filter an array of results to exclude items that have certain words within the string. I've searched and I think I've come fairly close. This is what I have so far:
$page is a multi-dimension array with 3 values, I am only concerned with the [0] value, the other values are not required.
$popular = array();
$validresults = array('blog','ans-blog','podcast');
$i = 0;
foreach ($results as $page) {
$string = $page[0];
$url_string = end(explode('/', $string));
if (in_array($url_string,$validresults)){
$popular[$i] = $page[0];
$i++;
}
}
sort($popular);
print_r($popular);
The final array should look something like this, with the only the required results.
[0] => /ans-blog/
[1] => /ans-blog/2009/07/24/blah-blah-blah-blah/
[2] => /ans-blog/2010/08/05/blah-blah-blah-blah/
[3] => /ans-blog/2011/05/04/blah-blah-blah-blah/
[4] => /ans-blog/2011/11/15/blah-blah-blah-blah/
[5] => /ans-blog/2012/09/26/blah-blah-blah-blah/
[6] => /ans-blog/2013/10/24/blah-blah-blah-blah/
[7] => /ans-blog/2013/11/30/blah-blah-blah-blah/
[8] => /ans-blog/2015/07/03/blah-blah-blah-blah/
[9] => /ans-blog/2018/07/23/blah-blah-blah-blah/
[10] => /blog/2009/08/blah-blah-blah-blah/
[11] => /blog/2015/02/blah-blah-blah-blah/
[12] => /blog/2015/06/blah-blah-blah-blah/
[13] => /blog/2015/07/blah-blah-blah-blah/
[14] => /blog/2017/02/blah-blah-blah-blah/
[15] => /blog/2018/07/blah-blah-blah-blah/
[16] => /home/
[17] => /home/2018t2-courses/
[18] => /home/on-demand-courses/
[19] => /home/steps-registration/
[20] => /moodle/course/view.php?id=12
[21] => /moodle/course/view.php?id=45
[22] => /moodle/login/index.php
[23] => /moodle/my/
[24] => /podcast/
I would like the end array to only have the items that have any of these array items in the URL:
array('blog','ans-blog','podcast');
I get this error:
PHP Notice: Only variables should be passed by reference in /var/www/vhosts/mydomain.org/httpdocs/mustread/HelloAnalytics.php on line 91
Thank you in advance for the assist.