How to pass an array in query string in PHP?
Hello everyone! I'm a beginner in PHP and ran into a problem. I need to pass an array of data via URL (query string) to another page. For example, I have a form with many checkboxes, and I want to pass the selected values as an array.
I tried doing this:
```php
$fruits = ['apple', 'banana', 'orange'];
$queryString = http_build_query(['fruits' => $fruits]);
// Result: fruits[0]=apple&fruits[1]=banana&fruits[2]=orange
```
But when I try to get the array on another page via $_GET, it comes as a regular string, not as an array. I read that PHP can parse such parameters itself, but for some reason it doesn't work for me. Maybe I'm doing something wrong?
Also I'm interested: is it possible to pass a multidimensional array? And how to properly handle such data on the server side?
No answers yet.
Log in to leave an answer
Blogs