how do I write two dimensional array in kotlin? in...
# announcements
m
how do I write two dimensional array in kotlin? in php we can write it very easily, such as
Copy code
$arr = [
    [
        "name" => "john"
    ],
    [
        "name" => "michael"
    ]
];
how do I achieve the above?
m
arrayOf(arrayOf(...), arrayOf(...))
, where
...
is what you want in the inner arrays
s
You’ll need mapOf for associative arrays
m
excuse me, gosh... really bother tho. wish the kotlin team adopt the square bracket notation just like php does
s
Copy code
listOf(
  mapOf(“name” to “John”),
  mapOf(“name” to “michael”)
)
But like, don’t do that. Don’t write PHP in Kotlin. You probably want to define a Person data class or something similar here
☝️ 7
m
how do I define the data class in this regard?
would you show me the complete code of this?
m
Copy code
data class Person(val name: String)

listOf(Person("John"), Person("michael"))
m
@Mark Murphy finally, the light is shed
💡 1
thank you
s
You should probably have a look at the docs. https://kotlinlang.org/docs/reference/data-classes.html
I would also recommend going through the Koans https://kotlinlang.org/docs/tutorials/koans.html
m
just for fun, trying to bend the language you could get close to square brackets notation: https://pl.kotl.in/yzsMKPkcB
👀 1