test if sent value is an array
How can I test if a posted value from ajax to php is an array. I have been trying for hours to figure out but cannot seem to find a way to test accurately for an array. I have tried 开发者_StackOverflow社区var_dump, print_r but still not sure. Is there a test in php that I could use to determine if ajax is posting an array. Looking at the code, I think it should be but cannot seem to pass values to ajax from php without getting undefined error.Thanks
php v5.1.6
for(var i = 0;i < $(this).val();i++) {
$("#BRVbrtrv_boxnumber").append('<div data-role="fieldcontain"><label for="BRVbrtrv_boxnumber" class="ui-input-text">Enter box ' + (i + 1) + ' number:</label><input type="text" name="BRVbrtrv_boxnumber['+i+']" id="BRVbrtrv_boxnumber['+i+']" class="BRV_boxnumber ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" /></div>')
}
to check if a variable is an array you can use is_array() http://php.net/manual/en/function.is-array.php
I advice sending a json object with ajax to your php or you can do it the xml way too.
peace
You can use is_array() in PHP.
http://php.net/manual/en/function.is-array.php
Javascript:
sending array ["a","b","c"]
PHP:
$data = json_decode($recieved_data);
if(is_array($data)){ /* HERE YOU ARE SURE IT IS ARRAY */ }
http://php.net/manual/en/function.is-array.php
http://php.net/manual/en/function.json-decode.php
精彩评论