Page 1 of 1

Got unwanted value in Array

Posted: Tue Jun 08, 2010 1:13 pm
by raulbolanos
Hellow guys,

I get a list of values from the database with the following query:

Code: Select all

$queryEncEmpr = "select prim_key from login where sector='EMIM'";
And then, I save them into a Array. After that, I display the array with print_r and I got an extra value called "Array" at the position 0. I don't know why it's saved there:

This is the code:

Code: Select all

 $result = mysql_query($queryEncEmpr, $conn);
	 //Arreglo de todas las empresas de un sector en especĂ­fico.
	 $primkeyLista[] = array();
	  
	 while ($primkey = mysql_fetch_array($result)){	 
	   array_push($primkeyLista, $primkey[0]);
	 }

print_r($primkeyLista); 
This is the pirnt_r result:

Array ( [0] => Array ( ) [1] => 9 [2] => 12 [3] => 1883028 [4] => 1886507 [5] => 7902337 [6] => 35365 [7] => 7902320 [8] => 342421 [9] => 1889259 [10] => 1888257 [11] => 2 [12] => 7902433 [13] => 7902494 [14] => 7902446 [15] => 1883078 [16] => 1888238 [17] => 13 [18] => 1 )

The one at the 0 position is the wrong one.

How this value has been saved there?

I appreciate any kind of help or explanation,

thank you in advance.

Re: Got unwanted value in Array

Posted: Tue Jun 08, 2010 1:19 pm
by AbraCadaver
This is assigning an empty array to the first element of the $primkeyLista array.

Code: Select all

$primkeyLista[] = array();
You want:

Code: Select all

$primkeyLista = array();

Re: Got unwanted value in Array

Posted: Wed Jun 09, 2010 8:42 am
by raulbolanos
AbraCadaver wrote:This is assigning an empty array to the first element of the $primkeyLista array.

Code: Select all

$primkeyLista[] = array();
You want:

Code: Select all

$primkeyLista = array();
Thank you,

it works perfectly.