M
M
Mark Eshkilev2021-06-15 14:30:47
PHP
Mark Eshkilev, 2021-06-15 14:30:47

How to fix php code?

Hello, please help, is there such a function

public function remove_icon($icon) {
    global $db;
    if(!isset($this->icon[$icon]))
      return;
    unset($this->icon[$icon]);
    $db->execute("UPDATE `players` SET `icon`='{$db->safe(json_encode($this->icon))}' WHERE `id`='{$db->safe($this->id)}'")or die($db->error());
  }


and there is such a use of this function , the problem is that when using this function, the json that this function forms is not quite correct for me, for example, take json - [{"id":"5"},{"id":"10 "}], if I want to remove "id":"5" from json, then the output is like this, {"1":{"id":"10"}}, how can I make it so that json was displayed after such a function like this - [{"id":"10"}]??? help me please
$pl->remove_icon((int) $_POST['icon']);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-15
@Rsa97

array_values()

$t = ['value0', 'value1'];
unset($t[0]);
print json_encode($t); // {"1":"value1"}
$t = array_values($t);
print json_encode($t); // ["value1"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question