Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php, is there an array to iterator converter?

Tags:

php

its good that there is iterator to array http://php.net/manual/en/function.iterator-to-array.php but is there anything to do it reversed?

like image 556
John Smith Avatar asked Oct 17 '25 02:10

John Smith


1 Answers

Yes, if reversed means just make an Iterator from a given Array.

$array = array(
  'a' => 1,
  2 => new stdClass,
  3 => array('subArrayStuff'=>'value')
);

$iterator = new ArrayObject($array);

$arrayAgain = iterator_to_array($iterator);

Try it.

http://php.net/manual/en/class.arrayobject.php

Please read also Difference between ArrayIterator, ArrayObject and Array in PHP.

like image 121
JustOnUnderMillions Avatar answered Oct 18 '25 18:10

JustOnUnderMillions



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!