V
V
Vlad2021-06-28 11:55:33
PHP
Vlad, 2021-06-28 11:55:33

How to delete a string inside an array that is in a constant?

I do the removal of all lines from the array if a match is found with my condition.
If I try to remove a line from the array through the unset () function and use ordinary variables, then everything works fine, if I use constants, then it writes errors.
As I found out, the error is written because the functions that I use to work with an array only support variables, if I try to use a constant, it writes an error.

define("MASIV", file('MASIV.txt');

  foreach (MASIV as $key => $value) {
    if (MASIV[$key] == 'СОВПАДЕНИЕ') {
      unset(MASIV[$key]);
      file_put_contents('MASIV.txt', implode(PHP_EOL, MASIV));
      }
  }


Question two:
Is it possible to remove a value from an array if the array is inside a constant? The unset function is only for variables, perhaps there is an analogue of this function to remove a line from an array, the array_splice function also writes an error "only variables can be passed". Or maybe I'm not deleting a line from the array at all in the right way?

And tell me please, am I doing the right thing by putting arrays inside a constant? It's just that there is a certain "database" in the .txt file, so that every time you don't pass it to functions through variables, I think it's possible to put it in a constant. But I don’t understand yet, maybe in the future if I want to somehow interact with this “DB” file, then new problems will surface due to the use of a constant,

Thank you very much for your reply ♥️.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question