Title: Some php code optimizing
Last modified: August 21, 2016

---

# Some php code optimizing

 *  [Myar](https://wordpress.org/support/users/myar/)
 * (@myar)
 * [13 years ago](https://wordpress.org/support/topic/some-php-code-optimizing/)
 * Hi!
 * Hope someone can help me to optimize the following code. I know, I can handle
   it with multidimensional arrays, but arrays and I are at war…
 *     ```
       if ( ! function_exists( 'get_genre_meta' ) ) :
       function get_genre_meta(){
       	$genres = array();
       	$systems = array();
       	$categories_list = '';
       	foreach((get_the_category()) as $category) {
       		$parentCatName = get_cat_name($category->parent);
       		if($parentCatName == 'Genre'){
       			$genres[] = $category->cat_name;
       		}
       		if($parentCatName == 'Systeme'){
       			$systems[] = $category->cat_name;
       		}
       	}
       	foreach($genres as $cat_name){
       			$categories_list .= '<a href="/'.strtolower($cat_name).'/"><img class="systems-list" src="http://www.lost-in-games.de/wp-content/themes/twentytwelve/images/minibuttons/'.strtolower($cat_name).'10.png" alt="'.$cat_name.'" title="'.$cat_name.'" /></a>';
       	}
       	foreach($systems as $cat_name){
       			$categories_list .= '<a href="/'.strtolower($cat_name).'/"><img class="systems-list" src="http://www.lost-in-games.de/wp-content/themes/twentytwelve/images/minibuttons/'.strtolower($cat_name).'10.png" alt="'.$cat_name.'" title="'.$cat_name.'" /></a>';
       	}
       	echo $categories_list;
       }
       endif;
       ```
   
 * You see, I will show in wich categories the articels are. There are categories
   for the genre and for the systems (yes, it is a games site). But the genres must
   be shown at first and the system at last. Is there a way to change the code to
   save resources?
 * best regards
    Myar

The topic ‘Some php code optimizing’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [Myar](https://wordpress.org/support/users/myar/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/some-php-code-optimizing/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
