How to program a PHP loop using an array?
<p>In a wordpress site for a dental clinic, there are several services (e.g. Orthodontics). These services are like "categories", using both names and slug-names. (e.g. Orthodontics / cat_orthodontics).</p>

<p>In the frontend, the services page shows every category, the name of the category and a description. I just need to put images related to every category.</p>

<p>I noticed that in the category file (category.php) that creates the area to show every one of these images, there are several lines that control the frontend:</p>

<pre><code>&lt;?php   
                    $args = array( 'taxonomy' =&gt; 'services_category', 'hide_empty' =&gt; '0', 'exclude' =&gt; $pixhealth_deps);                           
                    $pixhealth_categories = get_categories ($args);                             
                    if( $pixhealth_categories ):
                        foreach($pixhealth_categories as $pixhealth_cat) :
                            $pixhealth_t_id = $pixhealth_cat-&gt;term_id;
                            $pixhealth_cat_meta = get_option("services_category_$pixhealth_t_id");
                            $pixhealth_link = !isset($pixhealth_cat_meta['pix_serv_url']) || $pixhealth_cat_meta['pix_serv_url'] == '' ? get_term_link( $pixhealth_cat ) : $pixhealth_cat_meta['pix_serv_url'];
                ?&gt;                                      
                            &lt;div class="departments-item "&gt;
                                &lt;span class="icon-round bg-color_second helper"&gt;
                                    &lt;i class="icon &lt;?php echo esc_attr($pixhealth_cat_meta['pix_icon']) ?&gt;"&gt;&lt;/i&gt;
                                &lt;/span&gt;
                                &lt;/div&gt;
                                &lt;h3 class="ui-title-inner"&gt;&lt;?php echo wp_kses_post($pixhealth_cat-&gt;name) ?&gt;&lt;/h3&gt;
                                &lt;p class="ui-text"&gt;&lt;?php echo pixhealth_limit_words($pixhealth_cat-&gt;description, 20) ?&gt;&lt;/p&gt;
                                &lt;a class="btn btn_small" href="&lt;?php echo esc_url($pixhealth_link) ?&gt;"&gt;&lt;?php _e("READ MORE", "PixHealth") ?&gt;&lt;/a&gt;
                            &lt;/div&gt;
                &lt;?php                           
                         endforeach;
                    endif; ?&gt;
</code></pre>

<p>The "departments-item" creates every displayed service in the frontend:</p>

<p><code>&lt;div class="departments-item "&gt;</code></p>

<p>To put images I need to create a new div for every service and delete the <code>&lt;i class="icon"&gt;</code> because I don't want to show icons for every service. I need images.</p>

<p>So I tried this:</p>

<pre><code>&lt;?php   
                    $args = array( 'taxonomy' =&gt; 'services_category', 'hide_empty' =&gt; '0', 'exclude' =&gt; $pixhealth_deps);                           
                    $pixhealth_categories = get_categories ($args);                             
                    if( $pixhealth_categories ):
                        foreach($pixhealth_categories as $pixhealth_cat) :
                            $pixhealth_t_id = $pixhealth_cat-&gt;term_id;
                            $pixhealth_cat_meta = get_option("services_category_$pixhealth_t_id");
                            $pixhealth_link = !isset($pixhealth_cat_meta['pix_serv_url']) || $pixhealth_cat_meta['pix_serv_url'] == '' ? get_term_link( $pixhealth_cat ) : $pixhealth_cat_meta['pix_serv_url'];
                ?&gt;                                      
                            &lt;div class="departments-item "&gt;
                                &lt;!--&lt;span class="icon-round bg-color_second helper"&gt;
                                    &lt;i class="icon &lt;?php /*?&gt;&lt;?php echo esc_attr($pixhealth_cat_meta['pix_icon']) ?&gt;&lt;?php */?&gt;"&gt;&lt;/i&gt;
                                &lt;/span&gt;--&gt;
                                &lt;?php servicios=array('cirugia_oral','endodoncia','estetica_dental','implantes_dentales','odontopediatria','ortodoncia','periodoncia','rehabilitacion_oral');   ?&gt;
                                &lt;div class="inner-departments &lt;?php echo wp_kses_post($pixhealth_cat-&gt;name) ?&gt;"&gt;

                                &lt;/div&gt;
                                &lt;h3 class="ui-title-inner"&gt;&lt;?php echo wp_kses_post($pixhealth_cat-&gt;name) ?&gt;&lt;/h3&gt;
                                &lt;p class="ui-text"&gt;&lt;?php echo pixhealth_limit_words($pixhealth_cat-&gt;description, 20) ?&gt;&lt;/p&gt;
                                &lt;a class="btn btn_small" href="&lt;?php echo esc_url($pixhealth_link) ?&gt;"&gt;&lt;?php _e("READ MORE", "PixHealth") ?&gt;&lt;/a&gt;
                            &lt;/div&gt;
                &lt;?php                           
                         endforeach;
                    endif; ?&gt;
</code></pre>

<p>I added an array:</p>

<p><code>&lt;?php servicios=array('cirugia_oral','endodoncia','estetica_dental','implantes_dentales','odontopediatria','ortodoncia','periodoncia','rehabilitacion_oral');   ?&gt;</code></p>

<p>and added a line to create every div:</p>

<p><code>&lt;div class="inner-departments &lt;?php echo wp_kses_post($pixhealth_cat-&gt;name) ?&gt;"&gt;</code></p>

<p>I noticed on another line that: <code>&lt;?php echo wp_kses_post($pixhealth_cat-&gt;name) ?&gt;</code> echoes the name of every category, so I decided to use this inside my new div to create every category class.</p>

<p>However, I would like to use the names from the array and not the names from every category because some names have special characters like "ñ" and this cannot be used as a class.</p>

<p>I don't know how to relate the names of the categories to every item in the array, using perhaps a foreach for every item in the array with every name in the categories? The idea is to create a unique class for every category so I can then add images using CSS for every class.</p>

<p>If you have a better idea how I can add unique images to every class let me know. </p>

<p>Thank you for any help.</p>