- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有以下类(class):
<?php
/*
* Abstract class that, when subclassed, allows an instance to be used as an array.
* Interfaces `Countable` and `Iterator` are necessary for functionality such as `foreach`
*/
abstract class AArray implements ArrayAccess, Iterator, Countable
{
private $container = array();
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetExists($offset)
{
return isset($this->container[$offset]);
}
public function offsetUnset($offset)
{
unset($this->container[$offset]);
}
public function offsetGet($offset)
{
return isset($this->container[$offset]) ? $this->container[$offset] : null;
}
public function rewind() {
reset($this->container);
}
public function current() {
return current($this->container);
}
public function key() {
return key($this->container);
}
public function next() {
return next($this->container);
}
public function valid() {
return $this->current() !== false;
}
public function count() {
return count($this->container);
}
}
?>
然后,我有另一个类是 AArray 的子类:
<?php
require_once 'AArray.inc';
class GalleryCollection extends AArray { }
?>
当我用数据填充 GalleryCollection 实例然后尝试在 array_filter()
中使用它时,在第一个参数中,我收到以下错误:
Warning: array_filter() [function.array-filter]: The first argument should be an array in
最佳答案
因为 array_filter
只适用于数组。
查看其他选项,例如 FilterIterator
,或者首先从您的对象创建一个数组。
关于php - 为什么实现 ArrayAccess、Iterator 和 Countable 的类不能使用 array_filter()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3543161/
这个问题在这里已经有了答案: Using `$this` in an anonymous function in PHP pre 5.4.0 (5 个答案) 关闭 9 年前。 如果要执行以下操作:
array_filter — Filters elements of an array using a callback function array array_filter ( array $in
我正在使用 array_filter 来做这样的事情: function endswithy($value) { return (substr($value, -1) == 'y'); } $
我正在尝试对对象数组使用 array_filter,并使用 foo 类的公共(public)方法作为回调。我不知道该怎么做。 我得到了这个结果:Fatal error: Using $this whe
这个问题在这里已经有了答案: Is there a function to extract a 'column' from an array in PHP? (15 个答案) 关闭 9 天前。 我试
我正在使用 array_filter在 PHP 中,当名为 type 的键的值与特定字符串匹配时,拆分包含多个数组的数组。这是它的样子: 样本数组 $arr[] = Array ( [0] =
我有两个数组: $arr1 = array('a' => 10, 'b' => 20); $arr2 = array('a' => 10, 'b' => 20, 'c' => 30); 如何使用 ar
我有一个包含一些关联数组的索引数组,我应用了一个简单的 $my_arr = array_filter($my_arr, function($obj) { return $obj["value"
我得到了这个名为 $files[] 的多数组,它由如下键和值组成: [0] => Array ( [name] => index1.php [path] => http://local
我有以下代码: function lower_than_10($i) { return ($i < 10); } 我可以用来过滤这样的数组: $arr = array(7, 8, 9, 10,
我在 php 中使用 array_filter: $new_array = array_filter($updated, "check_if_value_is_null_or_false"); fun
我可以以及如何使用 PHP 的 array_filter 来过滤以下数组结构中的空白/空条目? 来自:该数组来自使用 Fetch BOTH 的 PDO 调用,因此在这种情况下数字值和命名值始终相等。
这个问题在这里已经有了答案: Reference: What is variable scope, which variables are accessible from where and what
我来自 JS 世界,无法理解这段代码: function getCountryName($code, $codes){ print_r($code); array_filter( $c
我对array_filter很熟悉,想往功能上想,但我想知道有没有办法保留被丢弃的值?例如,如果我有一个像这样的数组: 2; }); 结果将是:array( 3, 4 )。 有没有办法保留丢弃的值
我来自 JS 世界,无法理解这段代码: function getCountryName($code, $codes){ print_r($code); array_filter( $c
我对array_filter很熟悉,想往功能上想,但我想知道有没有办法保留被丢弃的值?例如,如果我有一个像这样的数组: 2; }); 结果将是:array( 3, 4 )。 有没有办法保留丢弃的值
一旦条件满足数组的一个元素,我们可以中断回调的执行吗? 例如。 $a = array(1,2,3,4,5); foreach($a as $val){ if ($val == 3){
这个问题在这里已经有了答案: array_count_values() with objects as values (3 个答案) 关闭 4 个月前。 如何防止为我要搜索的每个值重复相同的代码块?
我的方法的签名如下所示: public function ProgramRuleFilter(&$program, $today=null) { 当我这样调用它时, $programs = array
我是一名优秀的程序员,十分优秀!