0

I have an array like this:

$aSample = [
   'productName' => [
        'sample',
        'sample2'
    ],

   'productNumber' => [
        'numberOne',
        'numberTwo'
    ]
];

How can I make this array look like this one:

productName=sample,sample2&productNumber=numberOne,numberTwo

Thank you for the help in advance!

1
  • I just want to show it first in a dd() Commented May 20, 2020 at 11:15

1 Answer 1

1

I think this will work

$aSample = [
    'productName' => [
         'sample',
         'sample2'
     ],

    'productNumber' => [
         'numberOne',
         'numberTwo'
     ]
 ];

 $array = [];
 foreach($aSample as $key=>$item) {

    $arr = $key.'='.implode(',',$item);


    array_push($array,$arr);

}
echo implode('&',$array);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.