Home » Php » How to insert a new key value pair in array in php?

How to insert a new key value pair in array in php?

Posted by: admin April 23, 2020 Leave a comment

Questions:

I’ve an array as follows named $test_package_data. For the reference I’m printing first two elements of it:

Now I want to add a new key-value pair named [count] => '$some_value' in this array in every element after the key-value pair [test_pack_purchase_date](say after [test_pack_purchase_date] => 255. How should I do this? Can anyone help me in this regard? Thanks in advance.

How to&Answers:

If you are creating new array then try this :

$arr = array("key" => "value");

And if array is already created then try this :

$arr["key"] = "value";

Answer:

Answer:

Try this: