PHP uses curl to pass multidimensional array problems

Source: Internet
Author: User
Now we're going to write an API, but there's a problem with the transfer of multidimensional arrays when using curl to pass arguments
{        $post _data = Array (            ' auth-userid ' = + 611510,            ' api-key ' = ' API ', '            domain-name ' =>array (' Domain1 ', ' domain2 '),            ' tlds ' = ' com ', '        ;        $result =http_build_query ($post _data);              Var_dump ($result);    }

Start using the time has been the domain parameter loss error, and then look at the data passed, is this
String ' auth-userid=611510&api-key=api&
Domain-name%5b0%5d=domain1&domain-name%5b1%5d=domain2&tlds=com ' (length=93);

And I'm going to pass it on.
' auth-userid=611510&api-key=api&
Domain-name=domain1&domain-name=domain2&tlds=com '
So the transmission will not error, why use Http_build_query (), two-dimensional array will appear this%5b0%5d, and%5b1%5d, how to solve


Reply to discussion (solution)

In fact, the problem is very simple.
Http_build_query? Request string after generating Url-encode
The result is a string of URL encode. All of them have been given to encode.
You can use

$post _data = Array (            ' auth-userid ' = + 611510,            ' api-key ' = ' API ',            ' domain-name ' =>array (' domain1 ') , ' domain2 '),            ' tlds ' = ' com ', '        ;        $result =http_build_query ($post _data);              Var_dump ($result);        Var_dump (UrlDecode ($result));

In this way, the data is passed domain-name[0]=domain1&domain-name[1]=.

You are welcome to join the technology group to learn more about the technology 231566327

%5B0%5D is [] a pair of brackets
This is generated according to PHP rules.

If the other party is not PHP, press domain-name[] to access the Domain-name member
Or you can just erase it.
$result = Str_replace ('%5b0%5d ', ' ', Http_build_query ($post _data));

If the other side is PHP, it must not be deleted. Or we'll have less data.

That's still the address to the URL encode

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.