This is my array
$array=Array( 
                [0] => hell 
                [1] => for 
                [2] => sale 
                [3] => for 
                [4] => sale 
                [5] => earth 
                [6] => 0 
            )
and i want know how to remove last 4 elements from $array
and just i want get "hell for sale" from $array.any one know about this?
You can try array_splice.
Try this code snippet here
<?php
$array = Array(
    0 => "hell",
    1 => "for", 
    2 => "sale", 
    3 => "for", 
    4 => "sale", 
    5 => "earth", 
    6 => 0);
array_splice($array, count($array) - 4, 4);
print_r($array);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With