I need help with some PHP code. I am retrieving data from a MySQL database using left joins. Based on these records I am creating nested arrays which I want to be clean, e.g.:
array(
[0] = array(
[0] = array(
[0] = array(
[0] = array(
etc...
)
)
),
[1] = array(
[0] = array(
[0] = array(
[0] = array(
etc...
)
)
)
)
)
Now my idea is to create multiple arrays and then use the key to match them together, e.g.:
$array1 = array([0] => array(id = 0)); // value =
// match
$array2 = array([0] => array(...)); // key = id = value of the $array1 with key 0
Is it a good practice ? Or should I keep the nested arrays ?
A multidimensional array is an array containing one or more arrays.
A multidimensional array in MATLAB® is an array with more than two dimensions. In a matrix, the two dimensions are represented by rows and columns. Each element is defined by two subscripts, the row index and the column index.
Two – dimensional array is the simplest form of a multidimensional array.
There is nothing like a good or bad practice in such cases. All depends on what kind of work you are taking from arrays. If you want to access/traverse all arrays in your code in single time then it will be good to have them as nested arrays but if you need to traverse only one or two out of all then I think you should make them individual arrays rather than traversing all arrays just to access one or two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With