PHP how to Push an array to a value in another array (multidimensional array)?

First, your array needs to be an "associative array". You can create the array in one statement like this.

First, your array needs to be an "associative array". You can create the array in one statement like this: $myarray = array( 1233 => "", 4345 => 12, 3452 => "" ); Or one item at a time like this: $myarray = array(); $myarray1233 = ""; $myarray4345 = 12; $myarray3452 = ""; This is still one dimensional array. You can go one step further and create a multi-dimensional array like this: $myarray = array(); $myarray1233 = ""; $myarray4345 = array("PhotoID" => 12, "Location" => "Somewhere"); $myarray3452 = array(); $myarray3452"PhotoID" = 13; $myarray3452"Location" = "Somewhere else"; See the section on Arrays in PHP manual.It is a very frequently used data structure in PHP and I encourage you to read the section thoroughly.

Thank you thank you very much! – TaylorMac Oct 25 '11 at 6:37 will accept when it lets me – TaylorMac Oct 25 '11 at 6:37 1 Very nice. Hope you don't mind the slight edit (thought someone might find the link to the manual page useful).

– Tieson T. Oct 25 '11 at 6:39.

In PHP arrays works like that: $a = array("1233", "4345", "3452"); In the above example, the values, "1233", "4345" and "3452" they have each own an index number. So if you run that code: $a = array("1233", "4345", "3452"); echo ""; print_r($a); echo ""; you will get that result: Array ( 0 => 1233 1 => 4345 2 => 3452 ) In that case you can't assign an array on "4345" but on "1". So, with that in mind if you have another one array like that : $b = array("321", "654", "987"); and you like to assign it into position "1" then you have to do something like that: $a = array("1233", "4345", "3452"); $b = array("321", "654", "987"); $a1 = $b; TAKE CARE The above code will replace your value "4345" with the content of the array $b.

Now let's try to print out your array: $a = array("1233", "4345", "3452"); $b = array("321", "654", "987"); $a1 = $b; echo ""; print_r($a); echo ""; The result will be that now: Array ( 0 => 1233 1 => Array ( 0 => 321 1 => 654 2 => 987 ) 2 => 3452 ) Finaly, if you like to keep both the values "4345" from the array $a and assign an array to that same position into the array $a you have to consider what you like to do with the value "4345" Some ideas are here: $a = array("1233", "4345", "3452"); $b = array("321", "654", "987"); $b = $a1; $a1 = $b; echo ""; print_r($a); echo ""; The above code has that result: Array ( 0 => 1233 1 => Array ( 0 => 321 1 => 654 2 => 987 3 => 4345 ) 2 => 3452 ) Or you can try that: $a = array("1233", "4345", "3452"); $b = array("321", "654", "987"); $c = array(); $c = $a1; $c = $b; $a1 = $c; echo ""; print_r($a); echo ""; The above code will have the following result Array ( 0 => 1233 1 => Array ( 0 => 4345 1 => Array ( 0 => 321 1 => 654 2 => 987 ) ) 2 => 3452 ).

It looks like you want to create an associative array from an existing array. You can try this: $assoc_array = array_combine($myarray, array_fill(0, count($myarray), null)); $assoc_array'4345' = 12; $assoc_array will be filled with null values for all other eventIDs.

This code will produce what you want: $myarray = array("1233","4345","3452"); print_r($myarray); $eventID = 4345; $photoID = 12; if( in_array( $eventID, $myarray) ) { array_diff( $myarray, array($eventID) ); $myarray $eventID = $photoID; } print_r($myarray).

In that case why don't you try $myarray"4345"=12; which will end up and array like Array ( 0 => 1233 1 => 4345 2 => 3452 4345 => 12 ).

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