[Problem] Store stdclass to result? |
I have a code for get result of a table
And i need change some value in result to different and store it to new array, but it's impossible My code same PHP Code: function test($id) { When i using var_dump to check the $rs_new it same $rs, this sound mean the variable $rs_new not stored the new value of $cust But, when i using var_dump($cust) in foreach loop so the status change for variable $cust How can i do it for store? Thanks you for read!
Your code looks correct. Try to dump the object and the array in your function and just for testing add a new property to the object.
PHP Code: function test($id) { Are the dumps the same ?
That's because objects in PHP can not be dereferenced. At least not without a workaround.
Example: Code: $obj1 = new stdClass(); The workaround would be to cast object to array when copying and then casting the copied array to object. So I would suggest using arrays, but if you absolutely wish to keep it as an object: Code: function test($id) {
Website: http://tomaz.lovrec.eu
GitHub: https://github.com/slax0rr Twitter: https://twitter.com/slax0rr
You can set a new value for a proterty in objects
PHP Code: $obj1 = new stdClass();
I had short time and tested it like that
PHP Code: $rs = $this->db->get('table')->result(); It works as desired. You should check your call for the get()-Method: PHP Code: from
I did not say you can not set a property to an object. I only said objects can not be dereferenced in PHP without a workaround.
Example: PHP Code: $obj = new stdClass(); Quote:$ php test.php Foreach does exactly this: PHP Code: $a = $arr[0];
Website: http://tomaz.lovrec.eu
GitHub: https://github.com/slax0rr Twitter: https://twitter.com/slax0rr
@slax0r: you're right, but result() gives back an object witch you can iterate in a proper way.
|
Welcome Guest, Not a member yet? Register Sign In |