Got unwanted value in Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Got unwanted value in Array

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Got unwanted value in Array

Post 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();
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.
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Re: Got unwanted value in Array

Post 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.
Post Reply