0
How to short multidimensional array using php?
Shorting multiple dimensions array
5 odpowiedzi
+ 1
What do you mean by short it?
Isn't $x = [[1,2],[3,4]] short enough?
+ 1
Maybe you can use an objects and make it shorter with the constructor of the class something like this:
class Student
{
public $name;
public $lastName;
public $grades;
function __construct($name,$lastName,$grades)
{
$this->name=$name;
$this->lastName=$lastName;
$this->grades=$grades;
}
}
$x=[1=>new Student("potato","squad",[10,20,30]),4=>new Student("raul","kumar",[100,100,100])];
echo $x[1]->name;
Now you souldn't insert the name,lastname and grade field everytime. If you still want to do this with key value pair I would recommend you to use function that returns the structure you need or just use constants and array without store the "name" field always.
0
Potato Squad no, I want multi dimensions key value pair array shorting, for example. Array of students with their attributes.
0
Rahul Kumar Gupta something like this?
["Jack"=>[90,100,90], "Rahul"=>[100,100,100]]
0
No, I like $x =[1=>['name':'rahul']]