Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] (resolved) Adding objects to an array in php

Started by GameMasterXL Mar 24, 2006 at 7:18 PM 3 replies 550+ views
Original Post
GameMasterXL
GameMasterXL
How do i add an object to a php array? i have tried lots of methods and found no usefull info on google on this but i am tryig to make a function that adds a new object to an array every time its called but don't know how to do this i hope someone can help. [Edited by - GameMasterXL on March 25, 2006 6:36:38 AM]
silencer-
silencer-
function doSomething(&$array) // Note the pass by reference
{
$array['key'] = 'value';
}

$array = array('default' => 0);
doSomething($array);
print_r($array);
Sander
Sander
$array = new Array();$object = 'whatever';$array[] = $object;print_r($array);
GameMasterXL
GameMasterXL
Hi thanks for that that worked fine but now i am getting problems accesing a member function from the object in each array element like i do this in a for loop $object->foo(); and it gives me a parse error that the function is not in a defined object. How can i do this? thnx ones again.

Edit: ok i found this problem out now thnx.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.