public static function matchLabelWithID($labels) { $tagsWithIDs = []; foreach ($labels as $label) { $foundTag = Tags::findOne(['label' => $label]); if (!is_null($foundTag)) { //létezik ilyen cimke $tagsWithIDs[$foundTag->id] = $label; } else { //még nincs ilyen cimke -> mentjük if (trim($label) !== '') { $tag = new Tags(); $tag->label = $label; $tag->status = 'a'; $tag->save(); // már van ID-nk $tagsWithIDs[$tag->id] = $label; } } } return $tagsWithIDs; }