I have this array called $top, It consist of vehicle models like so -
$top = array('tacoma', 'corolla', 'camry');
I would like to know if any of these values exist in a for loop var called $title, im using this to get an rss feed. I have tried using array_search with no luck like so -
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$c++;
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('date')->item(0)->nodeValue,
);
array_push($feed, $item);
}
for($x=0;$x<$limit;$x++) {
$title = $feed[$x]['title'];
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$item = $feed[$x]['item'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
$desc = preg_replace('/[^A-Za-z0-9\-]/', ' ', $description);
$title = strtolower($title);
$find= array_search($top, $title);
if ($find) {
// insert all matches in database
} else {
echo 'nothing found';
}
}
Here is an example of what $title produces - toyota corolla ce low miles (chico) $4500. I would like to identify if corolla exist in the title using the array $top.
Here is what I get when I echo $title -
2012 chevy camaro 45th anniversary edition (chico/orland) $115002006 mitsubishi raider dura-cross pick-up for sale (yuba city, ca.) $59002016 dodge ram 2500 (corning) $430002016 dodge ram 2500 (corning) $4300020062007 toyota corolla ce low miles (chico) $4500 etc... So what I would like is to pull all titles that contain one of the strings in the $top array.
if-elseinsideforloop? I am unable to see. Also$top = array(tacoma, corolla, camry);is invalid, it need to be$top = array('tacoma', 'corolla', 'camry');. Also we don't know what is$feed? can you show it's values?Yes the if-else is inside the for loop? where? add it properly. not as separate logicarray_key_exists(). for more info w3schools.com/php/func_array_key_exists.asp