Assign value from one associative array of php into another array?

Yes $tempParams = $params Will copy all values from $params to $tempParams $params'foo' = 'bar'; echo $tempParams'foo'; //nothing $tempParams = $params; echo $tempParams'foo'; //'bar' $params'foo' = 'hai'; echo $tempParams'foo'; //still: 'bar.

Yes, $tempParams = $params; Will copy all values from $params to $tempParams. $params'foo' = 'bar'; echo $tempParams'foo'; //nothing $tempParams = $params; echo $tempParams'foo'; //'bar' $params'foo' = 'hai'; echo $tempParams'foo'; //still: 'bar.

Thank you man, your reply is worked for me. I even don't have the comiler php. But just follow all the reply and correct the logic... – Syed Tayyab Ali Mar 31 '09 at 18:35.

As far as whether or not your array is associative, read the documentation on mysql_fetch_array() As far as assignment goes, you actually can put it in one statement $tempParams = $params = mysql_fetch_array( $result, MYSQL_ASSOC ); This simple test shows that when you do an assignment like this, both variables are separate copies and not references. $a = $b = array( 1, 2, 3 ); $b1 = 'x'; echo ''; print_r( $a ); print_r( $b ); echo.

Until you assign to $b1, in your example, $a and $b are not separate copies. – grantwparks Sep 25 '09 at 3:10.

Yes, the = operator will copy the array exactly. You can check yourself: // get the $params from DB print_r ($params); // will output array contents $tempParams = $params; print_r ($tempParams); // must be the same as above There’s no such thing as “declaring” variables in PHP, but if you wish to say that $tempParams is an array somewhere before assigning, you can do it like this: $tempParams = array (); This will make $tempParams an array with no elements inside.

Following statement is really helpful to me. $tempParams = array (); – Syed Tayyab Ali Apr 1 '09 at 2:21.

For arrays, numeric and associative, the = operator will make a copy of the variable. And both variables are completely independent of one another. However, when dealing with objects, the = operator creates a reference to the object, and both variables point to the exact same object.

Thank you buddy. My problem has solved now... – Syed Tayyab Ali Apr 1 '09 at 2:18 Arrays are not copied during assignment according to my research, until one or the other variable is updated. It's called "copy on write".

– grantwparks Sep 25 '09 at 3:07.

Yes you can, but that could cause some kind of aliasing if you're dealing with Objects (depending on which PHP version you're using). Why is it that you want to copy the array? Can't you work with the same original variable ($params)?

I want to ignore some columns from database, because somebody has added new columns. While I want to retail old values of table, just in case if user access any old record.. – Syed Tayyab Ali Mar 31 '09 at 18:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions