Postgres Loop Through Array Php To Json Converter