M
M
My joy2020-05-12 20:37:32
PHP
My joy, 2020-05-12 20:37:32

How to remove an array element?

Hey!

Tell me what I missed in this life, that the below code does not work:

<?php
$arr = [];
$arr[] = 'AAA';
$arr[] = 'BBB';
$arr[] = 'CCC';

unset($arr['BBB']);

print_r($arr); // AAA, BBB, CCC

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2020-05-12
@t-alexashka

why should he work if your array does not have an element with the key BBB .

N
ninja op op, 2020-05-12
@kur4chyt

$arr = ['AAA','BBB','CCC'];
unset($arr['BBB']);
print_r($arr) //AAA,CCC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question