- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
iterator_to_array — Copy the iterator into an array
array iterator_to_array ( Traversable $iterator [, bool $use_keys = true ] )
它适用于所有 Traversable 接口(interface),但为什么我在以下代码中输入错误:
$data = array(
0 => array(
0 => 1,
),
1 => array(
0 => 2,
),
2 => array(
0 => 3,
1 => 4,
2 => 5,
),
3 => array(
0 => 6,
),
4 => array(
0 => 7,
),
);
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($data));
echo PHP_EOL, iterator_count($it); // 7 total correct
echo PHP_EOL, implode(iterator_to_array($it)); //745 instead of 1234567
echo PHP_EOL, implode(iterator_to_array($it, true)); //745 instead of 1234567
但是
foreach($it as $v)
{
echo $v ;
}
输出
1234567
最佳答案
这是因为 $use_keys
默认为 true(自 5.1 起),在扁平化时破坏数组键。您需要像这样禁用设置:
print_r(iterator_to_array($it, false));
// ^^^^^
如果您运行的是 PHP < 5.2.1,那您基本上就完蛋了 ;-)
关于php - iterator_to_array 截断输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13988123/
DatePeriod是一个用于处理重复日期的 PHP 类。它的方法数量非常有限。所以当我想用重复日期做基本的数组函数时,我必须将它复制到一个数组中 iterator_to_array .奇怪的是,复制
在下面的 PHP 脚本中,iterator_to_array 效率极低(我使用了分析器)。下面的代码有更好的选择吗? $new = []; $rows=(new Mongo())->table1->f
FROM PHP DOC iterator_to_array — Copy the iterator into an array array iterator_to_array ( Traversab
在 PHP 中使用迭代器时,您可以使用 iterator_to_array 函数来提取迭代结果的数组。例如,假设您有以下 ArrayObject: $array_object = new ArrayO
我很难理解 PHP 的 iterator_to_array 函数。 我尝试阅读手册,但没有帮助。 这是什么?我该如何使用它?什么是合适的用例? 最佳答案 简而言之,iterator_to_array(
在 MongoCursor 实例上使用 iterator_to_array() 可以在 PHP 5.3 中抛出异常吗?换句话说,我是否需要在 try-catch 语句中包装对 MongoCursor
mongo 类的 PHP 文档说 using a cursor而不是 iterator_to_array 更好。 为什么?我将从中获得什么好处/灵 active ? 最佳答案 使用 iterator_
我是一名优秀的程序员,十分优秀!