In this tutorial learn how to add value / Prepend a value to an array in php using array_unshift method
TUTORIAL
OUTPUT DEMO
function prependelement($array, $value)
{
array_unshift($array, $value);
return $array;
}
TUTORIAL
<?php
$array = Array
(
'3' => 10,
'2' => 2,
'5' => 'Nakiya',
);
/**
* Prepend a value to an array PHP
*/
function prependelement($array, $value)
{
array_unshift($array, $value);
return $array;
}
var_dump(prependelement($array,'Jack'));
array(4) {
[0]=>
string(4) "Jack"
[1]=>
int(10)
[2]=>
int(2)
[3]=>
string(6) "Nakiya"
}
No comments:
Post a Comment