Postgres Loop Through Array Php To Json Orient