Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

OK, here is the method,

I have an array called post

this one has these keys: id,title,description

i'm storing all my ids,titles and descriptions in those keys.

Now i work on my post titles,

i have another array called keywords

Thanks to @Dagon, i could check my keywords on my title array , so if the title contains some of these keywords i return those titles.

now my question is :

my returned titles that only contained some of the keywords i want to get its id and its description

EDIT

for example ,

$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
    }
  }
share|improve this question
    
You should post the smallest amount of code possible to duplicate the issue. – scragar May 27 '14 at 12:07
    
We are here to help you fix the errors of your code. Not to write it for you. Please, show what have you done so far and at what point are you stuck! – Dainis Abols May 27 '14 at 12:10
    
OK guys , check my edit :) – Hasan Zohdy May 27 '14 at 12:25

2 Answers 2

up vote 1 down vote accepted
$lang_name = array("php","html");

$languages = array(
    "id" => array("1","2","3"),
    "lang"=>array("php","html","css"),
    "version"=>array("PHP5","HTML5","CSS3")
);

The script to find ID and 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 );

And the result:

Array
(
    [php] => Array
        (
            [id] => 1
            [ver] => PHP5
        )

    [html] => Array
        (
            [id] => 2
            [ver] => HTML5
        )

)
share|improve this answer
    
Thanks buddy , that made the trick :) – Hasan Zohdy May 27 '14 at 12:49
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>';
  }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.