I want to save some data which is in array form and used this to save array but it will save Array keyword in this How to save array values with this.

$this->configWriter->save('my/path/whatever1', $newdata, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);

  • Could you please show sample data in the array. – Abdul Pathan Sep 9 '20 at 14:49
  • Prits, i thing you have do json_encode and save in core_config table. – Ketan Panchal Sep 9 '20 at 15:38

In order to save array in config database you can convert array to serialized string.

Inject Serializer Class in your constructor.

public function __construct( ...,
\Magento\Framework\Serialize\SerializerInterface $serializer) {
  /*** You other code ***/
  $this->serializer = $serializer;

Use the serialize() to convert array to serialized string.

$serializedData = $this->serializer->serialize($newdata);
$this->configWriter->save('my/path/whatever1', $serializedData, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);

You can convert the serialized string back to array wherever you wanna use the value as

$arrData = $this->serializer->unserialize($serializedData);

Hope it was helpful.


  • Thanks for the response. How to save the data with this data as an array value not want to log that ? @Abdul – Prits Sep 9 '20 at 14:30
  • Please find the updated answer. – Abdul Pathan Sep 9 '20 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.