I get an array using the function preg_match_all. The code is as it is:
$str = $dataGroups['groups'];
preg_match_all('/[0-9]/', $str, $matches);
It return an associated array from the type:
array(5) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" [3]=> string(1) "4" [4]=> string(1) "5" }
Where the values are actually id’s for a Link table, where I have two foreign keys, the values of the one FK are the values of the array above, what I need is to assign the keys with another value which should be the same for all elements because I\m gonna use it for multiple inserts in the table.So to make it clear If I want to insert all values which have id 67 I think I need something like this form my codeigniter active record:
array(5) { [67]=> string(1) “1” [67]=> string(1) “2” [67]=> string(1) “3” [67]=> string(1) “4” [67]=> string(1) “5” }
And use the AR command:
$this->db->insert(‘mytable’, $matches[0]);
I’m gonna try it for first time so any advice is appreciated, but the most important is to change the value of the keys with the same number, and maybe if you could tell if this is the right way to do the multiple insert using CodeIgniter AR.
Thanks
Leron
You cannot have duplicate keys in an array, they have to be unique as they are there for referencing!
However, what you could do it have an associative array like so: