xref: /PHP-5.6/Zend/tests/closure_047.phpt (revision 26522477)
1--TEST--
2Closure 047: Use in preg_replace_callback() using variables by reference
3--FILE--
4<?php
5
6function replace_variables($text, $params) {
7
8	preg_replace_callback( '/(\?)/', function($matches) use (&$params, &$text) {
9
10		$text = preg_replace( '/(\?)/', array_shift( $params ), $text, 1 );
11
12	}, $text );
13
14	return $text;
15}
16
17echo replace_variables('a=?', array('0')) . "\n";
18echo replace_variables('a=?, b=?', array('0', '1')) . "\n";
19echo replace_variables('a=?, b=?, c=?', array('0', '1', '2')) . "\n";
20echo "Done\n";
21?>
22--EXPECT--
23a=0
24a=0, b=1
25a=0, b=1, c=2
26Done
27