par
Dr@ke » 02 avr. 2010, 06:21
Oui il y a des tonnes de façons
$produit = array('pain', 'lait', 'chocolat');
$recherche = 'Pain lait cacahuète chocolat lait';
$recherche = array_unique(explode(' ', $recherche));
$recherche = array_intersect($produit, array_map('strtolower', $recherche));
// Les produits disponibles
print_r($recherche);
<?php
$produit = array('pain', 'lait', 'chocolat');
$recherche = 'Pain lait cacahuète chocolat lait';
$recherche = array_unique(explode(' ', $recherche));
foreach($recherche as $mot)
{
if(in_array(strtolower($mot), $produit))
{
echo sprintf('Nous avons ce produit : %s <br />', $mot);
}
else
{
echo sprintf('Pas de produit : %s <br />', $mot);
}
}
?>
Oui il y a des tonnes de façons :)
[php]$produit = array('pain', 'lait', 'chocolat');
$recherche = 'Pain lait cacahuète chocolat lait';
$recherche = array_unique(explode(' ', $recherche));
$recherche = array_intersect($produit, array_map('strtolower', $recherche));
// Les produits disponibles
print_r($recherche);[/php]
[php]<?php
$produit = array('pain', 'lait', 'chocolat');
$recherche = 'Pain lait cacahuète chocolat lait';
$recherche = array_unique(explode(' ', $recherche));
foreach($recherche as $mot)
{
if(in_array(strtolower($mot), $produit))
{
echo sprintf('Nous avons ce produit : %s <br />', $mot);
}
else
{
echo sprintf('Pas de produit : %s <br />', $mot);
}
}
?>[/php]