Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generic Array Question

Status
Not open for further replies.

thisguy

Programmer
Joined
Jan 29, 2003
Messages
9
Location
US
Good Afternoon,

I am currently building a web site using PHP and MySQL; I was just wondering if anyone could answer a generic question for me.

If I have the variable:
$Array_1 = array($Element1, $Element2, $Element3);

I then assign that array to another variable
$Temp_Var = $Array_1;

$Temp_Var then becomes a multi-dimensional array, so if I want to get the value of $Array_1[0], through $Temp_Var – I need to write $Temp_Var[0][0].

I was wondering if there is a way to assign $Array_1 to $Temp_Var, and not end up with a multi-dimensional array. I know I could create $Temp_Var as an array then run a loop to push the elements of $Array_1 into $Temp_Var, but it seems like there should be a more efficient way and I’m just missing something.

Any help would be great.

Thanks…
 
Sorry, PHP 4.3.x

I not actually at that computer, so I'm not sure of the exact version, but I do know it is atleast 4.3.something

Thanks...
 
Why would the assignment of $Array_1 to $Temp_Var change the structure?
Code:
<?php
$myArray = array(1,2,3);
print_r($myArray);

$temp = $myArray;
print_r($temp);
?>
The code produces the same result both in PHP 4.2.2 and 4.3.3
Code:
Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 )

Please show the code you use. There must be something else going on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top