更新时间:2022-12-12 13:45:49
要搜索数组中的元素,可以使用array_search
函数,而可以使用unset
函数从数组中删除元素.例如:
To search an element in an array, you can use array_search
function and to remove an element from an array you can use unset
function. Ex:
<?php
$hackers = array ('Alan Kay', 'Peter Norvig', 'Linus Trovalds', 'Larry Page');
print_r($hackers);
// Search
$pos = array_search('Linus Trovalds', $hackers);
echo 'Linus Trovalds found at: ' . $pos;
// Remove from array
unset($hackers[$pos]);
print_r($hackers);
您可以参考: https://www.php.net/manual/zh_cn/ref.array.php 获取更多与数组相关的功能.
You can refer: https://www.php.net/manual/en/ref.array.php for more array related functions.