Array_push - how to add specific key and value

How can I add specific key and value into array using array_push() in PHP ?
0
give a positive ratinggive a negative rating
20 Jun 2021 at 12:02 PM
Hi,

You can multiple ways how to add values into an array. When using an array_push(), the specific values are added into array.

To add specific keys and values into an array, you have to set keys in variable:

$arr = array();

$arr['name'] = 'Florian';
$arr['surname'] = 'Baker';

print_r($arr);

This array will look like:
array( 'name' => 'Florian' , 'surname' => 'Baker' );
0
give a positive ratinggive a negative rating
23 Dec 2022 at 05:13 PM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
Find us on Facebook
2023 AnswerTabsTermsContact us
How would you rate your experience with AnswerTabs ?
Very badVery good
Feedback
Thank you for your feedback.
Close