I need to add a key and value to an existing array and don't seem to get it together.
My existing array when printed is as follows:
Array ( [0] => stdClass Object ( [id] => 787 [name] => Steve [surname] => Ryan [email] => Steve@hotmail.com ) [1] => stdClass Object ( [id] => 1057 [name] => Peter [surname] => Smith [email] => Peter.Smith@yahoo.com ) [2] => stdClass Object ( [id] => 1058 [name] => Chris [surname] => Gill [email] => chrisgill@gmail.com ) )
I need to add some details to this array on the fly from string , which looks like this:
Topher: Topher1234@mac.com Elvis: elvispresley@gmail.com Marilyn: marilyn.monroe@hotmail.com
Each entry is separated by the new line symbol, and the name and email address are separated by the symbol :
So at the end, my array will look like this:
Array ( [0] => stdClass Object ( [id] => 787 [name] => Steve [surname] => Ryan [email] => Steve@hotmail.com ) [1] => stdClass Object ( [id] => 1057 [name] => Peter [surname] => Smith [email] => Peter.Smith@yahoo.com ) [2] => stdClass Object ( [id] => 1058 [name] => Chris [surname] => James [email] => chrisjames@gmail.com ) [3] => stdClass Object ( [id] => [name] => Topher [surname] => [email] => Topher1234@mac.com ) [4] => stdClass Object ( [id] => [name] => Elvis [surname] => [email] => elvispresley@gmail.com ) [5] => stdClass Object ( [id] => [name] => Marilyn [surname] => [email] => marilyn.monroe@hotmail.com ) )
I looked at array_push but couldn't handle it.
Any help on this is very much lit.
WITH
source share