Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PHP value from input using Tagify

Tags:

php

I have a problem with submitting a PHP form using jQuery Tagify.

If I add 2 tags like John and Thomas, then I'm getting $_POST['tag'] as:

'[{"value":"John"}, {"value":"Thomas"}]'

How I can change my $_POST['tag'] to get this POST as: John,Thomas?


1 Answers

var_dump(implode(', ', array_column(json_decode($_POST['tag']), 'value')));

First you decode the JSON coming in $_POST['tag'] into an array/object structure. array_column gives you the flat array with the values. Then you join it separated by commas (implode).

like image 104
Quasimodo's clone Avatar answered Sep 15 '25 13:09

Quasimodo's clone