jeudi 2 janvier 2020

PHP insert array associative - i want to insert a value to existing array in assosciative array

i got question How to insert value to a existing array, and my expetation of result is like :

Array
(
    [id] => 11
    [title] => Lorem ipsum
    [view] => 3445
)

But what i have did is :

<?php

$newVideo = [
    'id'=>'11',
    'title'=>'Lorem ipsum'            
];

$view = '3445';

$newVideo[] = ['view'=>$view];

print_r($newVideo);

and my result is :

Array
(
    [id] => 11
    [title] => Lorem ipsum
    [0] => Array
        (
            [view] => 3445
        )

)



Aucun commentaire:

Enregistrer un commentaire