-7

I have two arrays.

$a = array("one","two","three");
$b = array ( 0,1,2,3,4,5,6,7,8,9);
Kostas Mitsarakis
  • 4,772
  • 3
  • 23
  • 37

2 Answers2

2

Look at the user contributed example in 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);
}
clemens321
  • 2,103
  • 12
  • 18
0

You could create a mapping function and use array_map as follows:

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);
trincot
  • 317,000
  • 35
  • 244
  • 286