PHP implode on LUA

Asked

Viewed 138 times

2

I have the following code that passes a php array to JS:

var js_array_date1 = [<?php echo '"'.implode('","', $newarray_date1).'"' ?>];

My problem is how I can do this in LUA. Pass a LUA array to JS, I know I have to use the table.concat()

  • I don’t quite understand what you want to do, what’s wrong with using the table.concat()? have tried something like this? meuArray = table.concat({"foo", "bar", "baz"}).

1 answer

5


From what I understand (correct me if I’m wrong), you need a function that given a vector V and a separator S, returns a string with each of the elements in V concatenated in order and separated by S, in LUA we have the function table.Concat()(http://lua-users.org/wiki/TableLibraryTutorial) It exists in various forms, namely:

--Sem separador
> = table.concat({ 1, 2, "three", 4, "five" })
12three4five
--Com separador
> = table.concat({ 1, 2, "three", 4, "five" }, ", ")
1, 2, three, 4, five
--Com separador e indice inicial inclusivo (indices em LUA começam em 1)
> = table.concat({ 1, 2, "three", 4, "five" }, ", ", 2)
2, three, 4, five
--Com separador, indice inicial e final (inclusivos)
> = table.concat({ 1, 2, "three", 4, "five" }, ", ", 2, 4)
2, three, 4

Source:http://lua-users.org/wiki/TableLibraryTutorial Note that this function does not work in the case of nested tables

Browser other questions tagged

You are not signed in. Login or sign up in order to post.