Good day to all!

There is a code:

if (count($temp)){ foreach ($temp as $row){ if ($row->cat_state == 1){ $row->route = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug)); $related[] = $row; } } } 

The associative array $row->catslug has the value uncategorised . How to make a conclusion of all elements of the array not containing the value of uncategorised ?

    2 answers 2

    As far as is clear you want to make changes to Joomla Route , the easiest method to remove is uncategorised (not including in $row->route ) for example:

     if (count($temp)){ foreach ($temp as $row){ if ($row->cat_state == 1){ if($row->catslug == 'uncategorised'){ continue; } $row->route = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug)); $related[] = $row; } } } 

      Just filter by array_filter

       if (count($temp)){ foreach ($temp as $row){ if ($row->cat_state == 1){ $catslug = array_filter( $row->catslug, function($catSlugRow) { return $catSlugRow != 'uncategorised'; } ); $row->route = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug)); $related[] = $row; } } } 
      • Checked, filtering does not work, the array $ row-> catslug gets uncategorised. - Demon
      • How to change this row $ row-> route = JRoute :: _ (ContentHelperRoute :: getArticleRoute ($ row-> slug, $ row-> catslug)) so that the array $ row-> catslug does not fall uncategorized ???? - Demon
      • The array_filter function does not change the original array, but returns a modified one, which should be used, as I showed in the example. If it still does not work, then send the data from which you need to filter - Alexander Oleynikov