Problem using multidimensional array whithout initialisation
Posted: Wed Feb 17, 2010 5:24 pm
Hi everyone,
I'm running into some problems when using multidimensional arrays. What I want is an array containing multiple arrays, but using only two arrays: one multidimensional, the other one unidimensional.
Here's how it works:
- first I initialize the arrays
$multi_array = array(array());
$uni_array = array();
- then I need to retrieve some info on the web, that I want to store in an array
$uni_array[] = ("1");
$uni_array[] = ("blabla");
$uni_array[] = ("blablabla");
- then I want to store it in the multidimensional array, to be able to use it after
// I know that I need to copy the $uni_array and think the problem is here (tried to do it but never get it worked)
$multi_array[] = $uni_array;
unset($uni_array);
- then I retrieve some info again, and so on
$uni_array[] = ("14");
$uni_array[] = ("blabi");
$uni_array[] = ("blabloa");
$multi_array[] = $uni_array;
unset($uni_array)
I need to do that in order to sort the arrays by the first value (the integer) afterwards.
What is happening is that I have got nothing in the $multi_array at the end.
I think the problem is coming from $multi_array[] = $uni_array; but I don't know how to fix it, or maybe there is a better way to do what I want to do.
Thanks for the help.
I'm running into some problems when using multidimensional arrays. What I want is an array containing multiple arrays, but using only two arrays: one multidimensional, the other one unidimensional.
Here's how it works:
- first I initialize the arrays
$multi_array = array(array());
$uni_array = array();
- then I need to retrieve some info on the web, that I want to store in an array
$uni_array[] = ("1");
$uni_array[] = ("blabla");
$uni_array[] = ("blablabla");
- then I want to store it in the multidimensional array, to be able to use it after
// I know that I need to copy the $uni_array and think the problem is here (tried to do it but never get it worked)
$multi_array[] = $uni_array;
unset($uni_array);
- then I retrieve some info again, and so on
$uni_array[] = ("14");
$uni_array[] = ("blabi");
$uni_array[] = ("blabloa");
$multi_array[] = $uni_array;
unset($uni_array)
I need to do that in order to sort the arrays by the first value (the integer) afterwards.
What is happening is that I have got nothing in the $multi_array at the end.
I think the problem is coming from $multi_array[] = $uni_array; but I don't know how to fix it, or maybe there is a better way to do what I want to do.
Thanks for the help.