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
)
)
UPDATE QUESTION: in my case i have complex foreach in each foreach i want to store the value to variable array like this :
$newVideo = array();
foreach ($videos['items'] as $v){
$id = $v['snippet']['resourceId']['videoId'];
$title = $v['snippet']['title'];
$newVideo[] = [ "id" => $id ,"title" => $title];
the $newVideo is have ['id'] and ['title'] and i want to store ['view'] too, but i have to foreach function first to get the view data from ['id'] so i my code to foreach function to get a view is like :
$funcvid = array();
foreach($newVideo as $id){
$ids = $id['id'];
$vidview = YtJson('apilink', $ids, '');
array_push($funcvid, $vidview);
}
and i got the video statistic so i can grab the view data from that function, so i foreach again to store view data value with this code :
foreach($funcvid as $f){
foreach ($f['items'] as $h){
$view = $h['statistics']['viewCount'];
}
$newVideo['view'] = $view;
}
but for last foreach i can't store the value to $newVideo['view'], it won't lopping, and i got success if array is 2 dimensional, but my expetation is array is 1 dimensional