Creation d'un tableau multidimentionel
Bonjour
J'ai une liste de titre comme ce ci
Code:
1 2 3
| $array_title = array("fey palin" => 3 , "big theory" => 3 , "nyc through" => 3 ,
"jonas storm" => 3 , "bang theory" => 3 , "bang big" => 3 ,
"storm test" => 3 , "plain sahra" => 3 ,"mind woolf" => 3, "mind virginia" => 3); |
J 'essaye de regrouper les titres qui ont un mot en commun par exemple bang theory et bang big sont lié par le mot bang
sauf que je pense que j'ai un probleme dans la construction de mon tableau
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
$array_title = array("fey palin" => 3 , "big theory" => 3 , "nyc through" => 3 ,
"jonas storm" => 3 , "bang theory" => 3 , "bang big" => 3 ,
"storm test" => 3 , "plain sahra" => 3 ,"mind woolf" => 3, "mind virginia" => 3);
$new_array = array();
$i = 0;
foreach($array_title as $title => $value){
if(count($new_array) > 0){
$words = explode(' ',$title);
foreach($new_array as $key => $value){
if(strpos($key, $words[0]) || strpos($key, $words[1])){
$new_array[$title][] = $key; // << ça ne rentre rien dans mon tableau
}else{
$new_array[$title] = array();
}
}
}else{
$new_array[$title] = array();
}
$i++;
} |