Adam Ramadhan Adam Ramadhan - 5 months ago 21
PHP Question

deleting last array value ? php

1 question type

$transport = array('foot', 'bike', 'car', 'plane');


can i delete the plane ?
is there a way ?

2 question type

$transport = array('', 'bike', 'car', ''); // delate the last line
$transport = array('', 'bike', 'car', 'ferrari'); // dont the last line
$transport = array('ship', 'bike', 'car', 'ferrari'); // dont the last line


is there a easy way to delete the last array " if last array value is empty then delete " if not empty then don't delete ? but not to delete the first array ?

Answer
if(empty($transport[count($transport)-1])) {
    unset($transport[count($transport)-1]);
}