代替我有一个字符串:查找字符串文本和阵列
$string = 'I love my kitty and other animals.';
$categories = array(
'kitty' => 'cat',
'teddy' => 'bear',
'someting' => 'other',
);
我想就其中找到在阵列中的文本,并将其转换功能。 成才,如:
function find_animal_in_string($string)
{
// If $string contains one of the element in array print this array value
// how to do that?
}
所以我首选的结果将是:
echo $this->find_animal_in_string('I love my leon and other animals.') //echo cat
echo $this->find_animal_in_string('I do not like teddys in mountains.') //echo bear
会感谢你的帮助。我已经尝试strpos和array_key_exists,但没有为我工作。
这里有什么问题? – Calimero
如何制作打印结果的功能? – Tikky
做功能,打印结果?你有尝试过什么吗? – Calimero