glenelkins Posted April 2, 2009 Share Posted April 2, 2009 Hi I have two arrays; $winners = array ( $players_object_array[4] ); // this places the object at positoon 4 in this array in $winners $round_players[$r] = array of player objects; // $r refers to the round number and there are 3 players in there at keys 0,1,2 Now, i have to loop through thr $winners array and add each player to a specific position in the $round_players[$r] array as such $c = 1; foreach ( $winners as $key => $object ) { $position = ( $num_bye + $c ) - 1; // this will give 3 so the object should be placed at position 4 array_splice ( $round_players[$r], $position, 0, $object ); } but now when i loop throuh $round_players[$r] as $key => $object i get the following errors Notice: Trying to get property of non-object in C:\PHP\www\morebrackets\test.php on line 205 3=> Notice: Trying to get property of non-object in C:\PHP\www\morebrackets\test.php on line 205 4=> Notice: Trying to get property of non-object in C:\PHP\www\morebrackets\test.php on line 205 5=> whats confusing here is, there should be no array key 4 or 5, it should only be 0,1,2,3. now if i do some manual tests like: $array = array ( 'test1', 'test2','test3' ); array_splice ( $array, 2,0, 'test4' ); then loop through $array it works fine and outputs test1, test2, test4, test3 Quote Link to comment Share on other sites More sharing options...
glenelkins Posted April 2, 2009 Author Share Posted April 2, 2009 ha i figured it, i have to enforce the array on the object like so array_splice ( $array, $pos, $len, array ( $object ) ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.