I was trying to create a GET string to attach it to the end of a url like this -
$get_params = array(
'include' => array(
'enrollments',
'current_grading_period_scores'
),
'enrollment_type' => array(
'student',
),
);
$get_params = http_build_query($get_params);
$get_params = urldecode($get_params);
$url = $domain.$slug;
$url = $url.'?'.$get_params;
echo $url;
which prints out
include[0]=enrollments&include[1]=current_grading_period_scores&enrollment_type[0]=student
But my api didn't like the numbers in the square brackets, so I found a regular expression that removes the numbers -
preg_replace('/[[0-9]+]/', '[]', $get_params);
The final code, and the result -
$get_params = array(
'include' => array(
'enrollments',
'current_grading_period_scores'
),
'enrollment_type' => array(
'student',
),
);
$get_params = http_build_query($get_params);
$get_params = urldecode($get_params);
$get_params = preg_replace('/[[0-9]+]/', '[]', $get_params);
$url = $domain.$slug;
$url = $url.'?'.$get_params;
echo $url;
Prints out -
include[]=enrollments&include[]=current_grading_period_scores&enrollment_type[]=student
If someone knows of a better regex let me know, I'm kind of a noob with it.