Changing an associative array to an indexed array / getting Zend_Table_Row_Abstract as a non-associative

Hi, there, in Staxland. I was wondering if there is a function or an easy way to change an associative array into an indexed array.

To develop, I use the Zend framework, and I have a point on my site where I take the SQL table row as an associative array. I passed it javascript through echo in JSON. However, I noticed that I can see database column names in Firebug. Outsiders know that the names of your tables and columns are a great no-no security, so I would 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 be useful to have Zend_Table_Abstract-> fetchAll () return a non-associative array, but I don't think this is possible. Thanks for your help!

+48
php associative-array zend-framework associative
Jun 30 '09 at 18:10
source share
3 answers

Is pure php ok?

 $array = array_values($array); 

Source

+120
Jun 30 '09 at 18:40
source share

define function

 function array_default_key($array) { $arrayTemp = array(); $i = 0; foreach ($array as $key => $val) { $arrayTemp[$i] = $val; $i++; } return $arrayTemp; } 

Pass the associative array as a parameter, and it is converted to the default index for the array. For example: after calling the function, the Array Array(0=>43,1=>41) has Array('2014-04-30'=>43,'2014-04-29'=>41) .

+3
Jul 09 '14 at 10:10
source share

You can use this simple code snippet if you do not want to use the PHP built-in function.

 $input_array; // This is your input array $output_array = []; // This is where your output will be stored. foreach ($input_array as $k => $v){ array_push($output_array, $v); } print_r($output_array); 
-one
Dec 03 '15 at 10:26
source share



All Articles