PHP : Append a value to an array

In this tutorial learn how to add value to an array or Append a value to an array in php using array_push() method



function appendelement($array, $value)
    {
        array_push($array, $value);

        return $array;
    }

TUTORIAL



<?php

$array = Array
(
    '3' => 10,
    '2' => 2,
    '5' => 'Nakiya',

);
      
      
     /**
     * Append a value to an array.
     */
function appendelement($array, $value)
    {
        array_push($array, $value);

        return $array;
    }


var_dump(appendelement($array,100));
OUTPUT



array(4) {
  [3]=>
  int(10)
  [2]=>
  int(2)
  [5]=>
  string(6) "Nakiya"
  [6]=>
  int(100)
}

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...