kee2ka4 Posted August 24, 2008 Share Posted August 24, 2008 I have two arrays and I want to add the value of one array into another array. Here is the layout of both the arrays. The first array is called $res['id'], and has the value of 1. The second array is an array within an array and is called $routes, as shown below: $routes = array( array('url' => '/^(posts)?\/?(page\/)?(?P<page>\d?)$/', 'controller' => 'posts', 'view' => 'index')); I wanted to add $res['id'] (including the keyname) to the end of the $routes array and after adding the frist array, the second array will look like: $routes = array( array('url' => '/^(posts)?\/?(page\/)?(?P<page>\d?)$/', 'controller' => 'posts', 'view' => 'index', 'id' => '1')); How can I do this in php. Thanks, Ket Link to comment https://forums.phpfreaks.com/topic/121094-how-can-i-add-the-key-and-value-of-one-array-to-the-end-of-another-array-newbie/ Share on other sites More sharing options...
wildteen88 Posted August 24, 2008 Share Posted August 24, 2008 Does the $res array only hold the id? If so you could do $routes[0] += $res; However if $res holds more than one item, then you'll need to do $routes[0] += array('id' => $res['id']); Or alternatively (short/cleaner) $routes[0]['id'] = $res['id']; Link to comment https://forums.phpfreaks.com/topic/121094-how-can-i-add-the-key-and-value-of-one-array-to-the-end-of-another-array-newbie/#findComment-624255 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.