|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests |
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 16:00:02 2025 UTC |
Description: ------------ When printing an array using RecursiveTreeIterator, it'd be nice if it could handle new lines in the printed values without losing the tree prefix before every line after the first. Perhaps it'd make a good optional flag? Or does this option already exist but is undocumented? Test script: --------------- $array = array( 'a' => array( 'a1' => array(1, "lol\nlol\nlol", 3), 'a2' => array(3, 4, 5), ), 'b' => array( 'b1' => array(6, 7, 8), 'b2' => array(9), ), ); function print_ansi($array) { $rai = new RecursiveArrayIterator($array); $rti = new RecursiveTreeIterator($rai); $rti->setPrefixPart(0, ''); $rti->setPrefixPart(1, "\033(0\170\033(B "); $rti->setPrefixPart(2, " "); $rti->setPrefixPart(3, "\033(0\164\161\161\033(B "); $rti->setPrefixPart(4, "\033(0\155\161\161\033(B "); $rti->setPrefixPart(5, "\033(B"); foreach($rti as $value) { echo $value, PHP_EOL; } } print_ansi($array); Expected result: ---------------- ├── Array │ ├── Array │ │ ├── 1 │ │ ├── lol | | | lol | | | lol │ │ └── 3 │ └── Array │ ├── 3 │ ├── 4 │ └── 5 └── Array ├── Array │ ├── 6 │ ├── 7 │ └── 8 └── Array └── 9 Actual result: -------------- ├── Array │ ├── Array │ │ ├── 1 │ │ ├── lol lol lol │ │ └── 3 │ └── Array │ ├── 3 │ ├── 4 │ └── 5 └── Array ├── Array │ ├── 6 │ ├── 7 │ └── 8 └── Array └── 9