Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有数组:
$array=array('red'=>12,'blue'=>14,'violet'=>88,'green'=>58);
现在我想删除从键“紫罗兰色”开始的数组的所有值。所以我可以得到一个相当于:
$array=array('red'=>12,'blue'=>14);
如何在不循环所有数组的情况下实现这个目标?非常感谢!
数组切片( ),数组搜索( ) ,数组键( )
$array=array('red'=>12,'blue'=>14,'violet'=>88,'green'=>58); $new_array = array_slice($array,0,array_search("violet",array_keys($array))); print_r($new_array);
也许这有帮助:
array_slice($array,0,array_search("violet",array_keys($array)));