共計 343 個字符,預計需要花費 1 分鐘才能閱讀完成。
在 PHP 中,可以使用 array_search() 函數來搜索給定的值在數組中的位置。示例如下:
$fruits = array("apple", "banana", "orange", "pear");
$key = array_search("orange", $fruits);
if($key !== false){echo "The key of 'orange' in the array is: " . $key;
} else {echo "'orange' is not found in the array.";
}
上述代碼將輸出:The key of‘orange’in the array is: 2。這表示在數組 $fruits 中,值為 "orange" 的元素在索引位置 2 上。
丸趣 TV 網 – 提供最優質的資源集合!
正文完