CodeIgniter Forums
How do I push a value to a multidimensional array, before combining arrays? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How do I push a value to a multidimensional array, before combining arrays? (/thread-60993.html)



How do I push a value to a multidimensional array, before combining arrays? - El Forum - 08-21-2014

[eluser]BernardoLima[/eluser]
I need to push a value to a multidimensional array, before format it to an array with key => value.
My approach was the following:

Code:
$keys = array('column1','column2','column3','column4','column5');

foreach($multArray as $c => $subarr)
{
  array_push($multArray [$c],'1'); /* This line was supposed to push a value, that would be the value of column 5 */
  $multArray [$c] = array_combine($keys, $subarr); /* Combines the values array with the keys array */
}


print_r($multArray );

But it's not pushing the value.
It's returning me the error:
array_combine(): Both parameters should have an equal number of elements

Does someone knows how to corrrectly do that?


How do I push a value to a multidimensional array, before combining arrays? - El Forum - 08-21-2014

[eluser]CroNiX[/eluser]
What does $multArray look like?


How do I push a value to a multidimensional array, before combining arrays? - El Forum - 08-21-2014

[eluser]BernardoLima[/eluser]
Sorry for that, it was a silly mistake, please delete the thread, sorry.