note 118147 added to function.call-user-func-array
| From: | james dot patrick at lifeshop dot vn | Date: | Wed, 14 Oct 2015 04:00:36 +0000 |
| Subject: | note 118147 added to function.call-user-func-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203955@lists.php.net to get a copy of this message | ||
I've found the solution to resolve my need while writing the str_replace function for
processing the multi array as first two arguments of str_replace built-in function(although its pass
each array of argument 1 & 2)
<?php
// custom the str_replace function
function p_str_replace($argFind, $agrReplace, $theString) {
$needle_replace = $theString; // handle the string need to be replace
array_walk($argFind, function($val, $key) use(&$needle_replace, $agrReplace) {
$needle_replace = call_user_func_array('str_replace', array($val, $agrReplace[$key],
$needle_replace));
});
return $needle_replace;
}
// test
$the_str = array(
'coa' => ':col: :op1: :val: AND :col: :op2: :val:'
);
$ope = array('>=', '<=');
$colsdata = array('date_start', '2015-10-14');
echo p_str_replace(array(
array(':col:', ':val:'),
array(':op1:', ':op2:')
), array(
$colsdata,
$ope
), $the_str['coa']);
echo '-------------------------------' . "\n";
// more complexity
$complex = '(:col: :op1: :val: AND :col: :op2: :val:) AND (:col2: :op1: :val2: AND :col2: :op1:
:val2:)';
echo p_str_replace(array(
array(':col:', ':val:'),
array(':col2:', ':val2:'),
array(':op1:', ':op2:')
), array(
array('date_start', '2015-10-01'),
array('date_end', '2015-10-14'),
array('>', '<')
), $complex);
?>
Sorry about my bad English :)
Hope this help someone.
----
Server IP: 72.52.91.14
Probable Submitter: 14.161.4.219
----
Manual Page -- http://php.net/manual/en/function.call-user-func-array.php
Edit -- https://master.php.net/note/edit/118147
Del: integrated -- https://master.php.net/note/delete/118147/integrated
Del: useless -- https://master.php.net/note/delete/118147/useless
Del: bad code -- https://master.php.net/note/delete/118147/bad+code
Del: spam -- https://master.php.net/note/delete/118147/spam
Del: non-english -- https://master.php.net/note/delete/118147/non-english
Del: in docs -- https://master.php.net/note/delete/118147/in+docs
Del: other reasons-- https://master.php.net/note/delete/118147
Reject -- https://master.php.net/note/reject/118147
Search -- https://master.php.net/manage/user-notes.php