+ 1

Create array of type Person

I've created a class called Person and would like to know if it is possible to create an array of that class type. I am able to do it in Java so I was just curious.

20th Oct 2017, 4:57 PM
Hasan Tariq
Hasan Tariq - avatar
6 Answers
+ 1
I've tried $people = array() and then $person = new Person(...) to add it into the array.. Thanks!
20th Oct 2017, 6:31 PM
Hasan Tariq
Hasan Tariq - avatar
+ 6
Person [ ] persons = new Person [5]; for(int i=0; i<persons.length; i++){ persons [i] = new Person(); // or you can take user input }
20th Oct 2017, 6:21 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 5
Sorry for not noticing Php tag! My code was for Java. It's good that your problem is already solved :)
20th Oct 2017, 6:34 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 4
For sure it's possible except person is an abstract class.
20th Oct 2017, 5:12 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Oh no, its okay :) thanks for the help though!
20th Oct 2017, 6:36 PM
Hasan Tariq
Hasan Tariq - avatar
0
Oh okay, I'm new to OOP PHP. I've created two classes (both in the same file). How would I go about creating the array?
20th Oct 2017, 5:19 PM
Hasan Tariq
Hasan Tariq - avatar