How do I parse the true and false string in an array to become boolean if they exist?
For instance,
form
$config = array(
"allow_n" => "true",
"allow_m" => "false",
"say" => "hello"
);
to
$config = array(
"allow_n" => true,
"allow_m" => false,
"say" => "hello"
);
Is it possible?
EDIT:
Thanks guys for the help.
Sorry I forgot to clarify from the beginning – this case may happen in a multidimentinal array, for instance,
$config = array(
"allow_n" => "true",
"allow_m" => "false",
"say" => "Hello",
"php" => array(
"oop" => "true",
"classic" => "false"
)
);
you can use
array_walk_recursiveto achieve this :Example
Output Before
Output After