我需要以数组的形式获取字符串中字符的所有位置。我知道 php 函数strpos()
,但它不接受数组作为参数。
这是必需的:
$name = "australia"; //string that needs to be searched
$positions_to_find_for = "a"; // Find all positions of character "a" in an array
$positions_array = [0,5,8]; // This should be the output that says character "a" comes at positions 0, 5 and 8 in string "australia"
问题:什么循环可以帮助我构建一个可以帮助我实现所需输出的函数?