plastik77 Posted August 19, 2008 Share Posted August 19, 2008 hi, i'm trying to find a way to prepend values (uri data) to keys in an associative array which i've created from values in my database. this should be straightforward i'm sure but i can't find the right process to do this! i'm generating a dropdown list populated with values from my database, and all i want to do is to be able to modify the keys in the array as I need to make them part of a url e.g [senior/art/54] => [First and Second Year Art] - any ideas on the best way to do this array manipulation? so i use this neat ORM function to create an associative array - PHP Code: $page_children = $page_children->select_list('id', 'name'); this creates an array as follows: Array ( [54] => First and Second Year Art [55] => Standard Grade Art [56] => Higher/Intermediate 2 Art [57] => Advanced Higher Art ) Any help appreciated! Link to comment https://forums.phpfreaks.com/topic/120402-help-prepending-values-to-keys-in-associative-array/ Share on other sites More sharing options...
genericnumber1 Posted August 19, 2008 Share Posted August 19, 2008 Hopefully this is what you want... <?php $test = array('stuff'); print_r($test); // [0] => 'stuff' foreach($test as $var => $val) { $newTest['prependme!'.$var] = $val; } print_r($newTest); // ['prependme!0'] => 'stuff' ?> Link to comment https://forums.phpfreaks.com/topic/120402-help-prepending-values-to-keys-in-associative-array/#findComment-620364 Share on other sites More sharing options...
plastik77 Posted August 19, 2008 Author Share Posted August 19, 2008 cheers generic, that's exactly what i was looking for! Link to comment https://forums.phpfreaks.com/topic/120402-help-prepending-values-to-keys-in-associative-array/#findComment-620399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.