2

How to pass an array as a url parameter ? I'm using http_build_query(), array_shift() and urldecode().

I have this array:

$array = array(
    'phone' => array('ios', 'android', 'windows')
);

When i use http_build_query and urldecode will return:

phone[0]=ios&phone[1]=android&phone[2]=windows

When i use array_shift will return:

0=ios&1=android&2=windows

I want to this:

test.php?phone=ios&phone=android&phone=windows

Please help me. How to remove(hide) index from array.

Thanks in advance.

0

1 Answer 1

0
$queryString = "?phone=" . create_query_string(array('ios','windows','android'));
$array = create_array_from_query_string(substr($queryString, 7));

function create_query_string($array) {

    return implode('&phone=', $array);
}

function create_array_from_query_string($queryString) {

    return explode('&phone=', $queryString);
}

I suggest using above approach. But you must be familiar with your query string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.