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. Quote Link to comment Share on other sites More sharing options...
Solution lawless Posted September 14, 2014 Author Solution 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; Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.