skip to Main Content

Currently I have this url with paramanters. The $filter is in string format and rawurlencoded. Is it possible to use an array instead of string for the $filter? Like array('groups'=>array('11','22','33'))?
Here’s a sample code that is working.

$endpoint = 'https://api.com/queries';
$filter = "groups:['11', '22', '33']";
$url = $endpoint . '?filter=' . rawurlencode($filter);

It produces this url:

https://api.com/queries?filter=groups%3A%5B%2711%27%2C%20%2722%27%2C%20%2733%27%5D

2

Answers


  1. What is your expected result? Show us..please

    Login or Signup to reply.
  2. Try to use urlencode() function just after to use json_encode() function like this :

    $endpoint = 'https://api.com/queries';
    
    $filterArray = array('groups' => array('11', '22', '33'));
    
    $filter = urlencode(json_encode($filterArray));
    
    $url = $endpoint . '?filter=' . $filter;
    
    

    After this you can decode the URL-encoded JSON string and convert it back to an array like this :.

    $filterString = $_GET['filter'];
    $filterArray = json_decode(urldecode($filterString), true);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search