I've got a quick PHP question, which I'm sure some of the developers here can easily answer.
I've got the following array:
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Array
(
[0] => stdClass Object
(
[embed_count] => 3526
[stream_count] => 10216
[category] => gaming
[channel_count] => 20331
[format] => live
[featured] => 1
[site_count] => 6690
[abuse_reported] =>
[channel] => stdClass Object
(
[timezone] => America/New_York
[subcategory] =>
[category] => gaming
[embed_enabled] => 1
)
[video_height] => 720
[language] => en
[video_bitrate] => 2107.9375
[id] => 4426520352
[broadcaster] => delay
[broadcast_part] => 3
[audio_codec] => uncompressed
[up_time] => Mon Dec 24 09:46:39 2012
[video_width] => 1280
[geo] => US
[channel_view_count] => 18592346
[channel_subscription] => 1
[embed_enabled] => 1
[stream_type] => live
[video_codec] => AVC
)
[1] => stdClass Object
(
[embed_count] => 14
[stream_count] => 195
[category] => gaming
[channel_count] => 312
[format] => live
[featured] => 1
[site_count] => 181
[abuse_reported] =>
[channel] => stdClass Object
(
[timezone] => US/Pacific
[subcategory] =>
[category] => gaming
[embed_enabled] => 1
)
[video_height] => 1080
[language] => en
[video_bitrate] => 4398.9375
[id] => 4426659824
[broadcaster] => fme
[broadcast_part] => 2
[audio_codec] => uncompressed
[up_time] => Mon Dec 24 10:16:06 2012
[video_width] => 1920
[geo] => US
[channel_view_count] => 5738728
[channel_subscription] => 1
[embed_enabled] => 1
[stream_type] => live
[video_codec] => AVC
)
)
Now I want to add user_id to it and foreach loop through the array afterwards.
How can I add a new value to the existing array?
So I end up keeping the same array but with the added value, something like this:
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Array
(
[0] => stdClass Object
(
[user_id] => Twiebie
[embed_count] => 3526
[stream_count] => 10216
etc...
etc...
)
[1] => stdClass Object
(
[user_id] => AnotherUser
[embed_count] => 14
[stream_count] => 195
etc...
etc...
)
)
If I do something like:
PHP
1
2
3
4
5
// $result is the array as seen above here
foreach($useridas$value)
{
$result[] = $value;
}
It adds it to the bottom of the array instead of to the stdClass Object.
This is fine too, but how would I loop through it then? With a foreach inside a foreach? Can someone provide a code example?