如何将结果作为数组(一,二,三,一,二,三,一,二,三,一)

时间:2015-11-21 20:22:21

标签: php arrays

我有两个阵列。

$a = array("one","two","three");
$b = array ( 0,1,2,3,4,5,6,7,8,9);

2 个答案:

答案 0 :(得分:2)

查看http://www.php.net/manual/en/class.infiniteiterator.php

中用户提供的示例
$obj = new stdClass();
$obj->Mon = "Monday";
$obj->Tue = "Tuesday";
$obj->Wed = "Wednesday";
$obj->Thu = "Thursday";
$obj->Fri = "Friday";
$obj->Sat = "Saturday";
$obj->Sun = "Sunday";

$infinate = new InfiniteIterator(new ArrayIterator($obj));
foreach (new LimitIterator($infinate, 0, 14) as $value ) {
    print($value . PHP_EOL);
}

答案 1 :(得分:0)

您可以创建映射函数并使用array_map,如下所示:

function numToName($num) {
    return array("zero","one","two","three","four","five",
                 "six","seven","eight","nine")[$num];
}

$b = array (0,8,2,3,7,5,6,0,4,1);   
$result = array_map("numToName", $b);
print_r($result);