How to join int array into one string

45 Views Asked by At

So i have this array of errorcodes "codes": [ 597, 197, 120, 113 ] that I'm trying to combine into one string with a delimiter of "-". I was hoping to try to use $join() but since it only accepts array of string, it will not work. Is there any workaround to join these integers or like convert it into an array of string instead?

Output that I'm looking for: 597-197-120-113

1

There are 1 best solutions below

0
lchristmann On BEST ANSWER

As you have pointed out, the $join function only works for an array of strings.

What you can do however, is transform the numbers array beforehand into a string array by using the $map function, which is shown as an example in its documentation.

$join($map(codes, $string), "-")

outputs

"597-197-120-113"