how to get last array element in php
<?php
$source_array = ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'];
$result = end($source_array);
echo "Last element: ".$result;
?>
how to get last array element in php
<?php
$source_array = ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'];
$result = end($source_array);
echo "Last element: ".$result;
?>
php last item of array
echo end(['Gon', 'Killua', 'Hisoka']) // print Hisoka
slice array php
array_slice() function is used to get selected part of an array.
Syntax:
array_slice(array, start, length, preserve)
*preserve = false (default)
If we put preserve=true then the key of value are same as original array.
Example (without preserve):
<?php
$a=array("red","green","blue","yellow","brown");
print_r(array_slice($a,1,2));
?>
Output:
Array ( [0] => green [1] => blue )
Example (with preserve):
<?php
$a=array("red","green","blue","yellow","brown");
print_r(array_slice($a,1,2,true));
?>
Output:
Array ( [1] => green [2] => blue )
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us