Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change an associative array into an indexed array / get an Zend_Table_Row_Abstract as non-associative

Hi out there in Stackland. I was wondering if there was either a function or an easy way to change an associative array into an indexed array.

To elaborate, I'm using the Zend framework, and I've got a point in my site where I take out a row of an SQL table as an associative array. I've passed it to javascript via an echoed in JSON. However, I've noticed that I can see the names of my database's columns in Firebug. Having outsiders know the names of your tables and columns is a big security no-no, so I'd like to change it from

SQLarray[user_id] SQLarray[block_id] SQLarray[b_price] etc. 

to

SQLarray[0] SQLarray[1] SQLarray[2] etc. 

Is there a good way to do this?

It would also work to be able to have a Zend_Table_Abstract->fetchAll() return a non-associative array, but I don't think that's possible. Thanks for your help!

like image 891
Ethan Avatar asked Jun 30 '09 18:06

Ethan


People also ask

Does In_array work for associative array?

in_array() function is utilized to determine if specific value exists in an array. It works fine for one dimensional numeric and associative arrays.

What do associative arrays use for indexes?

Associative arrays differ from normal, fixed-size arrays in that they have no predefined limit on the number of elements, the elements can be indexed by any tuple as opposed to just using integers as keys, and the elements are not stored in preallocated consecutive storage locations.

What is the difference between an array and an associative array?

The keys of an indexed array are integers, beginning at 0. Indexed arrays are used when you identify things by their position. Associative arrays have strings as keys and behave more like two-column tables. The first column is the key, which is used to access the value.


1 Answers

Is pure php ok?

$array = array_values($array); 

Source

like image 68
Ian Elliott Avatar answered Oct 22 '22 10:10

Ian Elliott