如何将键列表数组与 wordpress post 与 array_intersect 的 "cat_name" 数组进行比较
How to compare an array of list of keys with an array of "cat_name" of wordpress post with array_intersect
我创建了这段代码:
<?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);?>
但是没用。
$displaycat 显示:Array ( [0] => Accueil [1] => Evénements [2] => hatha-yoga [3] => Sections ).
print_r($onesection)的结果;是一个空数组而不是 Array([0] => hatha-yoga.
我的目标是获取类别名称"hatha-yoga"之一post生成一个link到return本节[=24]的主页=].
您的 $displaycat
条目有尾随 space ($displaycat[] = $cat->cat_name . ' ';
)。你的 $lisections
没有。
试试 $displaycat[] = $cat->cat_name;
(没有串联)。
我创建了这段代码:
<?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);?>
但是没用。
$displaycat 显示:Array ( [0] => Accueil [1] => Evénements [2] => hatha-yoga [3] => Sections ).
print_r($onesection)的结果;是一个空数组而不是 Array([0] => hatha-yoga.
我的目标是获取类别名称"hatha-yoga"之一post生成一个link到return本节[=24]的主页=].
您的 $displaycat
条目有尾随 space ($displaycat[] = $cat->cat_name . ' ';
)。你的 $lisections
没有。
试试 $displaycat[] = $cat->cat_name;
(没有串联)。