Hi I wanted to know how i could remove a lore line. here is my code, it works I just dont know how to remove the line. PHP: foreach($lore as $line) { if(stripos($line, $this->getCEName($id))) { var_dump("it does"); //var_dump($line[]); } return true; }
Well, you could try it for yourself... Or you could think it through logically: how can you use a foreach function to get the key along with the array data? Spoiler: Answer: PHP: foreach($arr as $key => $data) {} After your check on the data returns true that it is what you want to delete, how do you use the array key to delete the data from the array? Spoiler: Answer: PHP: foreach($arr as $key => $data) { if($yourCheckHere) { unset($arr[$key]); $item->setLore($arr); }} Now you get to adjust your code to what you learned
You could find the index with array search. $lores = $item->getLore(); $index = array_search("Some Lore", $lores); unset($lores[$index]); $item->setLore($lores); You can use foreach loop also as Jason said