好的,这是方法,
我有一个名为post
的数组这个有这些键: ID,标题,说明
我将所有ID,标题和说明存储在这些键中。
现在我正在处理我的帖子,
我有另一个名为keywords的数组
感谢@Dagon,我可以在我的标题数组上查看我的关键字,所以如果标题包含其中一些关键字,我会返回这些标题。
现在我的问题是:
我返回的标题只包含了一些我想要获取其ID及其描述的关键字
修改
例如,
$lang_name = array("php","html");
$languages = array(
"id" => array("1","2","3"),
"lang"=>array("php","html","css"),
"version"=>array("PHP5","HTML5","CSS3")
);
foreach($lang_name as $lang){
if(in_array($lang,$languages['lang'])){
echo $lang."<br>";
// now i want to get the version and id of the languages for php and html values
}
}
答案 0 :(得分:1)
$lang_name = array("php","html");
$languages = array(
"id" => array("1","2","3"),
"lang"=>array("php","html","css"),
"version"=>array("PHP5","HTML5","CSS3")
);
查找ID和VERSION的脚本:
$new_arr = array();
foreach( $languages['lang'] as $key => $lng )
{
if ( in_array( $lng, $lang_name ) )
{
$new_arr[$lng] = array( 'id' => $languages['id'][$key],
'ver' => $languages['version'][$key]
);
}
}
print_r( $new_arr );
结果:
Array
(
[php] => Array
(
[id] => 1
[ver] => PHP5
)
[html] => Array
(
[id] => 2
[ver] => HTML5
)
)
答案 1 :(得分:0)
foreach($lang_name as $index => $lang){
if(in_array($lang,$languages['lang'])){
echo $lang."<br>";
// now i want to get the version and id of the languages for php and html values
echo $languages['id'][$index]. ' : '. $languages['version'][$index].'<br>';
}
}