Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unset last item of array

Tags:

arrays

regex

php

in this code i try to unset first and last item of $status array
to unset but the last item that i tried place thier pointer in $end
not unset what can I do for this reason?


$item[$fieldneedle] = " node_os_disk_danger ";
$status = preg_split('/_/',$item[$fieldneedle]);
unset($status[0]);
$end = & end($status);
unset($end);


in this example i need os_disk

like image 251
AmirModiri Avatar asked Jan 12 '11 12:01

AmirModiri


People also ask

How can I remove the last item in an array?

The Array pop() method is the simplest method used to remove the last element in an array. The pop() method returns the removed element from the original array.

How do you insert and remove the last element of an array?

The array_pop() function, which is used to remove the last element from an array, returns the removed element.

How do you remove the last two elements of an array?

Use the splice() method to remove the last 2 elements from an array, e.g. arr. splice(arr. length - 2, 2) . The splice method will delete the 2 last elements from the array and return a new array containing the deleted elements.

How can I change the last element of an array in PHP?

Answer: Use the PHP array_pop() function You can use the PHP array_pop() function to remove an element or value from the end of an array. The array_pop() function also returns the last value of array.


1 Answers

array_shift($end); //removes first
array_pop($end); //removes last
like image 172
Diablo Avatar answered Nov 10 '22 18:11

Diablo