不包括以'#'在PHP的foreach开始数组键? [英] Excluding array keys that start with '#' from foreach in PHP?
本文介绍了不包括以'#'在PHP的foreach开始数组键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用的'#'一个preFIX表明,一个给定的数组键包含元数据,而不是实际值的Drupal的形式排列。我怎样才能通过,除了那些键开始以'#'所有数组元素循环?
I have a Drupal form array that uses a prefix of '#' to indicate that a given array key contains metadata instead of actual values. How can I loop through all array elements except those whose keys begin with '#'?
推荐答案
您可以使用的 继续
跳到下一个迭代在循环时,用#
当前键启动。拿到第一个字符的一个方法是使用 SUBSTR()
。
You can use continue
to skip to the next iteration in your loop when the current key starts with a #
. One way to get the first character is using substr()
.
foreach ($array as $key => $value) {
if (substr($key, 0, 1) === '#') continue;
//do stuff
}
这篇关于不包括以'#'在PHP的foreach开始数组键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文