improved code by using array_map and echo