Welcome Guest, Not a member yet? Register   Sign In
Adding additional element to multidimensional array
#1

[eluser]mabright[/eluser]
In my controller I call my model to get an array of postings (ads posted by users). The array returned looks like what you see below. Before I display the array contents in my view, I want to add an encrypted version of the post ID. I am having issues trying to insert a new array element with the new value.

Code:
Array
(
    [0] => Array
        (
            [post_id] => 6
            [status] => 1
            [uid] => 6
            [posted_on] => 2012-01-07 08:50:39
            [post_title] => hey hey hey
        )

    [1] => Array
        (
            [post_id] => 5
            [status] => 1
            [uid] => 6
            [posted_on] => 2012-01-07 08:42:06
            [post_title] => blah blah blah
        )
)

I want to add an element called "encrypted_post_id". I have tried the below code but it adds a new element as "0", i.e. the entry in the array as [0] => N1bKWfztfISEx4H2DqmK2JzTkCnuLsQb7w/SJb4PzQzP9puzHiDfIBa9xo/lJ4rhv69kbmXx+8DlZXXahiLWRg==.

Code:
foreach($content['posts'] as $key => $value)
{
  array_push($content['posts'][$key],$this->encrypt->encode($value['post_id']));
}

Any help getting the proper element name and value added will be appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB