lawless Posted September 14, 2014 Share Posted September 14, 2014 Hello there again! I have the following construct of array now (schematics): array[0] array[id] = "1" array[title] = "title" array[1] array[id] = "3" array[title] = "another title" Now what i want to do, is to assign the parent-array keys to the IDs of it's contents. This is what it should look like: array[1] array[id] = "1" array[title] = "title" array[3] array[id] = "3" array[title] = "another title" How do I do that again? I know I did this some years ago, but I can not remember how. Link to comment https://forums.phpfreaks.com/topic/291061-numerate-array-by-one-of-its-arrays-values/ Share on other sites More sharing options...
lawless Posted September 14, 2014 Author Share Posted September 14, 2014 Just after sending I realized the solution I can simply name the array I am using directly at the source, when it first gets written. foreach ( $array_dbtable as $key => $value ) { $this->array_dbtable[$value['id']] = $value; } My old approach: $this->array_dbtable = $array_dbtable; Link to comment https://forums.phpfreaks.com/topic/291061-numerate-array-by-one-of-its-arrays-values/#findComment-1491092 Share on other sites More sharing options...
jcbones Posted September 14, 2014 Share Posted September 14, 2014 If you know that the array key will always be the id, why couldn't/wouldn't you do: $this->array_dbtable[$value['id']] = $value['title']; making it array( 1 => 'title', 3 => 'another_title ) Thus making it a simple array, instead of multidem. Link to comment https://forums.phpfreaks.com/topic/291061-numerate-array-by-one-of-its-arrays-values/#findComment-1491113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.