Arlene Mariano Arlene Mariano - 2 months ago 6
PHP Question

two-dimensional array inside two-dimensional arrays in php

Is it possible to achieve something like this? A two-dimensional array containing two-dimensional jagged array?

$jobOrder = array(array(1, "Web Developer", 100,
array(array(1, "PHP", 1),
array(2, "HTML", 1), array(3, "JAVA", 1)),
array(array(1, "pleasing personality", 1),
array(2, "english skills", 1)), 0),
array(2, "Senior Programmer", 50,
array(array(3, "Phython", 1),
array(5, "RUBY", 1),
array(10, "c#", 1)),
array(array(5, "good social skills", 1),
array(11, "management skills", 1))));


I want to store Job Order details into an array that should contain an orderID, job title, number of openings, skills(may have multiple skills so stored in an array; 2-d because I also wanted to store skillID, skill name and flag: if its been removed or not), qualifications(may have multiple qualifications same with skills), requirements and benefits (also same with skills). I would like to know how to access it.

Answer

You can access element like this:

$jobOrder = array(array(1, "Web Developer", 100, 
                        array(array(1, "PHP", 1),
                              array(2, "HTML", 1), array(3, "JAVA", 1)),
                        array(array(1, "pleasing personality", 1), 
                              array(2, "english skills", 1)), 0), 
                 array(2, "Senior Programmer", 50, 
                       array(array(3, "Phython", 1), 
                             array(5, "RUBY", 1), 
                             array(10, "c#", 1)), 
                       array(array(5, "good social skills", 1), 
                             array(11, "management skills", 1))));

 print_r($jobOrder[0][3]);

I will print the array and also you can access the elements in the array also by adding further indexes.

Comments