<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
	<channel>
		<title>cotonti.com : PHP array question</title>
		<link>https://www.cotonti.com</link>
		<description>Last topic posts</description>
		<generator>Cotonti</generator>
		<language>en</language>
		<pubDate>Thu, 23 Apr 2026 00:53:03 -0000</pubDate>

		<item>
			<title>Twiebie</title>
			<description><![CDATA[<p>
	Awesome, that is exactly what I need!</p>
<p>
	Thanks a lot for the quick reply, Trustmaster!</p>
]]></description>
			<pubDate>Mon, 24 Dec 2012 20:50:18 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7277&d=0#post36625]]></link>
		</item>
		<item>
			<title>Trustmaster</title>
			<description><![CDATA[<p>
	The <em>stdClass Object</em> thingie tells you that the array is not an array of arrays but is rather an array of <a href="http://php.net/manual/en/language.types.object.php" rel="nofollow">Objects</a>.</p>
<p>
	Another thing is that you might want to access items from both arrays by index, so you can use <a href="http://php.net/manual/en/control-structures.for.php" rel="nofollow">for</a> loop instead of <a href="http://php.net/manual/en/control-structures.foreach.php" rel="nofollow">foreach</a>.</p>
<p>
	Putting it all together, here is how you can add user_id property to each object in the array using values from another array:</p>
<pre class="brush:php;">
for ($i = 0; $i &lt; count($userid); $i++)
{
	$videos[$i]-&gt;user_id = $userid[$i];
}</pre>
<p>
	 </p>
]]></description>
			<pubDate>Mon, 24 Dec 2012 20:41:07 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7277&d=0#post36622]]></link>
		</item>
		<item>
			<title>Twiebie</title>
			<description><![CDATA[<p>
	I've got a quick PHP question, which I'm sure some of the developers here can easily answer.</p>
<p>
	I've got the following array:</p>
<pre class="brush:php;">
Array
(
    [0] =&gt; stdClass Object
        (
            [embed_count] =&gt; 3526
            [stream_count] =&gt; 10216
            [category] =&gt; gaming
            [channel_count] =&gt; 20331
            [format] =&gt; live
            [featured] =&gt; 1
            [site_count] =&gt; 6690
            [abuse_reported] =&gt; 
            [channel] =&gt; stdClass Object
                (
                    [timezone] =&gt; America/New_York
                    [subcategory] =&gt; 
                    [category] =&gt; gaming
                    [embed_enabled] =&gt; 1
                )

            [video_height] =&gt; 720
            [language] =&gt; en
            [video_bitrate] =&gt; 2107.9375
            [id] =&gt; 4426520352
            [broadcaster] =&gt; delay
            [broadcast_part] =&gt; 3
            [audio_codec] =&gt; uncompressed
            [up_time] =&gt; Mon Dec 24 09:46:39 2012
            [video_width] =&gt; 1280
            [geo] =&gt; US
            [channel_view_count] =&gt; 18592346
            [channel_subscription] =&gt; 1
            [embed_enabled] =&gt; 1
            [stream_type] =&gt; live
            [video_codec] =&gt; AVC
        )

    [1] =&gt; stdClass Object
        (
            [embed_count] =&gt; 14
            [stream_count] =&gt; 195
            [category] =&gt; gaming
            [channel_count] =&gt; 312
            [format] =&gt; live
            [featured] =&gt; 1
            [site_count] =&gt; 181
            [abuse_reported] =&gt; 
            [channel] =&gt; stdClass Object
                (
                    [timezone] =&gt; US/Pacific
                    [subcategory] =&gt; 
                    [category] =&gt; gaming
                    [embed_enabled] =&gt; 1
                )

            [video_height] =&gt; 1080
            [language] =&gt; en
            [video_bitrate] =&gt; 4398.9375
            [id] =&gt; 4426659824
            [broadcaster] =&gt; fme
            [broadcast_part] =&gt; 2
            [audio_codec] =&gt; uncompressed
            [up_time] =&gt; Mon Dec 24 10:16:06 2012
            [video_width] =&gt; 1920
            [geo] =&gt; US
            [channel_view_count] =&gt; 5738728
            [channel_subscription] =&gt; 1
            [embed_enabled] =&gt; 1
            [stream_type] =&gt; live
            [video_codec] =&gt; AVC
        )
)</pre>
<p>
	Now I want to add user_id to it and foreach loop through the array afterwards.</p>
<p>
	How can I add a new value to the existing array?<br />
	So I end up keeping the same array but with the added value, something like this:</p>
<pre class="brush:php;">
Array
(
    [0] =&gt; stdClass Object
        (
            [user_id] =&gt; Twiebie
            [embed_count] =&gt; 3526
            [stream_count] =&gt; 10216
            etc...
            etc...
        )

    [1] =&gt; stdClass Object
        (
            [user_id] =&gt; AnotherUser
            [embed_count] =&gt; 14
            [stream_count] =&gt; 195
            etc...
            etc...
        )
)</pre>
<p>
	If I do something like:</p>
<pre class="brush:php;">
// $result is the array as seen above here
foreach ($userid as $value)
{
    $result[] = $value;
}</pre>
<p>
	It adds it to the bottom of the array instead of to the <span style="background-color:rgb(245,245,245);color:rgb(51,51,51);font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:12px;line-height:18px;">stdClass Object</span>.<br />
	This is fine too, but how would I loop through it then? With a foreach inside a foreach? Can someone provide a code example?</p>
<p>
	Thanks in advance.</p>
]]></description>
			<pubDate>Mon, 24 Dec 2012 19:25:09 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/forums?m=posts&q=7277&d=0#post36620]]></link>
		</item>
	</channel>
</rss>