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.
Problem using multidimensional array whithout initialisation
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Problem using multidimensional array whithout initialisation
Works great for me after I fix the parse error because of the missing ; on the last unset() line:
You'll end up with an extra empty array in the first element so you want to change $multi_array = array(array()); to $multi_array = array();
Code: Select all
//- 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);
print_r($multi_array);Code: Select all
Array
(
[0] => Array
(
)
[1] => Array
(
[0] => 1
[1] => blabla
[2] => blablabla
)
[2] => Array
(
[0] => 14
[1] => blabi
[2] => blabloa
)
)mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Problem using multidimensional array whithout initialisation
hum well that's weird ... really don't work on my website!