BahBah Posted December 21, 2009 Share Posted December 21, 2009 Hello I have an array $data which contains post data sent to my user class. In this array will be an element called "group". Everything apart from "group" (which signifies the group the user is to be assigned) is inputted into the database in a single SQL insert. So after escaping the $data is imploded for the table field names and values for the SQL query. I would like to remove "group" and its corresponding value from the $data array and set the group value to a variable. I then intend to execute another query adding this user (last_insert_id) into a different table. Is this possible ? I've been looking through the PHP documentation and haven't been able to find anything suitable. I suppose one solution would be to use: $group = $data['group']; // then unset($data['group']) but it doesn't seem very elegant. Thank you Link to comment https://forums.phpfreaks.com/topic/185917-determining-and-removing-an-element-of-an-array/ Share on other sites More sharing options...
cags Posted December 21, 2009 Share Posted December 21, 2009 I'm not sure why you don't think that is elegant, your objective is to remove a value from an array and still have the value for later use, which is exactly what those two lines of code do. Link to comment https://forums.phpfreaks.com/topic/185917-determining-and-removing-an-element-of-an-array/#findComment-981745 Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 That function is what you were looking for. Just because it's not complicated doesn't mean it wont work... Link to comment https://forums.phpfreaks.com/topic/185917-determining-and-removing-an-element-of-an-array/#findComment-981747 Share on other sites More sharing options...
BahBah Posted December 21, 2009 Author Share Posted December 21, 2009 Thank you for your replies Link to comment https://forums.phpfreaks.com/topic/185917-determining-and-removing-an-element-of-an-array/#findComment-981889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.