0

I wanted to save the data in this format into database option field:

{"type":"type_value"}

I am getting data in post varaibles like this

$type_value = $request->input('type_value');
$type = $request->input('type');

How Can I save this in database? I have tried this

$data['options'] = array($type,$type_value);

But by this it is saving in this format:

["Qualifiers","1"]

I even tried doing this:

$data['options'] = json_encode(array($type,$type_value));

Instead it is saving like this

"[\"Qualifiers\",\"1\"]"

how can I do this?

1
  • serialize it and save it and then unserialize it when trying to access it Commented Feb 7, 2018 at 7:24

1 Answer 1

2

You just have to change your array definition. Your array considers 2 different elements i.e type and type_value. So just make your array with key value pair and you are all set.

json_encode(array($type => $type_value))  

Check this :- Fiddle

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.