I need to convert an array such as this:
$arr = array(1, 2, 3) ;
to this format:
arr[0]=1&arr[1]=2&arr[2]=3
is there any built in function in php or i must create this my self?
expected output should require key name in input data array, see below and after that use http_build_query() function to created query string
<?php
$arr = array("arr" => array(1, 2, 3)) ;
echo http_build_query($arr);
?>
encode output default
arr%5B0%5D=1&arr%5B1%5D=2&arr%5B2%5D=3
and if you need decode output then
<?php
$arr = array("arr" => array(1, 2, 3)) ;
echo urldecode(http_build_query($arr));
?>
arr[0]=1&arr[1]=2&arr[2]=3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With