my normal function call is ok and gives me back what i want.
but with the call_user_func and also with the call_user_func_array,
I experimented a lot and always give me back an wrong result.
Sorry but iam noobie
so the normal function call :
$key = ("msg_exists");
ArrayNoKeyMessage ($key,$GetJsonArray);
gives me back :
the message exists
but if i want to call call_user_func
$key = ("foo");
call_user_func('ArrayNoKeyMessage',$key,array('$GetJsonArray')) ;
give me always back
the message dont exists
it seams that call_user_func can not read succesfully $GetJsonArray ?
here the whole code example
<?php
$GetJsonArray = [
"foo" => "bar",
"bar" => "foo",
"msg_exists" => "the message exists",
];
function ArrayNoKeyMessage($key,$GetJsonArray)
{
if (!array_key_exists($key, $GetJsonArray)) {
echo 'the message dont exists';
} else {
echo $GetJsonArray["$key"].PHP_EOL."";
}
}
$key = ("msg_exists");
ArrayNoKeyMessage ($key,$GetJsonArray);
$key = ("foo");
call_user_func('ArrayNoKeyMessage',$key,array('$GetJsonArray')) ;
New contributor
al-naba project is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.