i have to send this array with nested arrays
$tags=[];
foreach ($importedTags->tags as $key => $value) {
$tags[]=array(
"name"=>$value->getName(),
"id"=>$value->getId(),
);
}
the array (if there were 3 importedTags) may look like this :
array(3) {
[0]=> array(2) { ["name"]=> string(14) "foo" ["id"]=> string(7) "3375095" }
[1]=> array(2) { ["name"]=> string(12) "bar" ["id"]=> string(7) "3378925" }
[2]=> array(2) { ["name"]=> string(8) "foobar" ["id"]=> string(7) "3405555" }
}
as a GET query parameter on a url
i tryed
$params=array(
"pageId"=>$pageId,
"tags"=>urlencode(implode(",", $tags))
);
return $this->redirect($this->generateUrl('my_route.create_sth',$params));
but when i parse it like
$tags=urldecode($request->query->get('tags'));
$tags=explode(",",$tags);
it returns to
array(3) {
[0]=> string(5) "Array"
[1]=> string(5) "Array"
[2]=> string(5) "Array"
}
and i know why its like this, and this makes sense
but i´m a php newbie, so how can i solve this and get a string representation like i tryed to get with implode and explode to get array back with such nested arrays?
var_dump) with the string contentArray. You're most likely trying to cast an array to a string at some point.$tagsis a bi-dimensional array. You have$tags[$item]["name"]and$tags[$item]["id"], so a mereimplodedoes not convert it into flat string. What value do you want to send on GET, name or id?