Postgresql Loop Over Array Php Functions