How to convert array data into Serialize format Magento 2.

Serialize array data using Magento 2 by natve SerializerInterface class.

The serialize method is used for storing or passing PHP values without losing their data type and structure.

serialize() method is used for serializing the data in Magento 2.

Use Magento\Framework\Serialize\SerializerInterface interface to create serialize data using Magento 2.

call from a template or other class,
You can pass a value as a string, array, int or any type to convert data into serializing format.

echo $this->setSerializeData();

Output:
{“code1″:”value1”}

Check the link for, Get serailize value using Magento 2.