There is a price data array obtained using serialize. It looks like this: s:6:"5443.7";s:4:"5443";s:6:"5442.3";s:6:"5442.2";s:6:"5441.9";s:6:"5441.4";s:6:"5441.3";s:6:"5440.9";s:6:"5439.7";s:6:"5439.6";s:6:"5439.4";s:6:"5439.3";s:6:"5439.2";s:4:"5439";s:6:"5438.1";s:6:"5437.7";s:6:"5437.5";s:4:"5437";s:6:"5436.7";s:6:"5436.6";s:6:"5436.2";s:4:"5436";s:6:"5435.5";s:6:"5435.4";s:6:"5435.1";

Now I try to insert it into the database, the field is of type varchar

  $mysqli->query("UPDATE book SET ask='$price' WHERE coin='123' "); 

But of course only the value of s is inserted: 6: "5435.1"; How to insert the whole array?

  • Inserting serialized data is a bad idea. It is better to store json. - ArchDemon
  • In the past your question I wrote the answer how to store data. But the second time you can’t ask a question correctly, it’s not clear why you want to store this data and how to use it. - Dodik
  • @Dodik periodically I will need to get the data from the database and use it in the table - Bertly
  • @Dodik the problem is not even in the type of stored data, but that only the last value of the array is inserted, although the insert request is inside the foreach loop - Bertly
  • @Bertly pack in json and save it. And you keep the last value because UPDATE, not INSERT - Dodik

1 answer 1

Try writing an array to a json string using json_encode ($ array) and writing it in this form and then after getting it from the database just use json_decode ($ content)