1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP(Laravel)でPostgresのhstoreを連想配列にコンバートする方法

Posted at

#初めに
現在仕事でReact、Laravel、postgresを使っているがDBから取得したhstoreの連想配列化で少し詰まったので連想配列化の方法を書いておこうと思い書いてます。

###コンバートコード


public static function hstoreConvert($data){
    return json_decode('{' . str_replace('"=>"', '":"', $data) . '}', true);
}

一回文字列上でjsonの形にstr_replaceで修正し、json_decodeでPHPの連想配列に置き換えている

###まとめ
よりいい方法があるとは思うがとりあえずこのコードで正常に動作する。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?