I’m sending a PHP script data converted from JSON into serialised form by JQuery (see http://api.jquery.com/jQuery.ajax/). PHP interprets the POST data as one big associative array, which is awesome.
What I’m wondering is, is it possible to cast to a boolean array in PHP? And generally, whether you can cast to a typed array in PHP?
At the moment I have an array of booleans in JavaScript which is interpreted as an array of string in PHP. I’m guessing you can’t cast in that way, as a PHP array can contain a mix of types?
Are you saying, you want to convert to something like:
to
?
Then, you could use something like this:
If you want to perform a “real” cast, instead (so, a string will evaluate to false only if == “”), just change the code in the callback function, to do a cast (
(bool)$sin this case), or whatever you need.