-1

i have created this code :

 <?php 
             $lisections = array('anglais','boxe-thai','Cyclotourisme','Danse-modernjazz–grs–classique','danse-sportive','dessin-peinture','escrime','Espagnol','gym-tonic','gymnastique-de-detente','gymnastique-enfantine-et-sportive','Gymnastique-senior','handball','hatha-yoga','histoire-de-lart','judo - ju jitsu','Karate','kendo-iaido','natation','ninjutsu','petanque','photo-club','randonnees-pedestres','refection-fauteuils','Sportives','subaquatique','tennis-de-table','tennis-de-table–senior','Tir','gym-dentretient-top-gym','sections-arts-martiaux','sections-langues','sections-gymnastique', 'section-aquatique','section-tennisdetable' );
            foreach((get_the_category()) as $cat) { 
                                $displaycat[] = $cat->cat_name . ' '; 
             }
              //print_r($displaycat);
            $onesection=array_intersect($lisections,$displaycat);
            print_r($onesection);?>

but it doesn't work.

$displaycat display that : Array ( [0] => Accueil [1] => Evénements [2] => hatha-yoga [3] => Sections ).

The result of print_r($onesection); is an empty array instead of Array([0] => hatha-yoga.

My target is to get one of categories name "hatha-yoga" of one post to generate a link to return to the main page of this section "hatha-yoga".

1
  • 1
    This is a typo question. You nonsensically sabotaged the intersection process by appending a space to each encountered word. Commented Mar 8, 2024 at 22:42

1 Answer 1

0

Your $displaycat entries have a trailing space ($displaycat[] = $cat->cat_name . ' ';). Your $lisections don't.

Try $displaycat[] = $cat->cat_name; (without the concatenation).

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.