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
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' );
Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us