What I'm doing is taking a basic array, with default numeric keys:
$basic_array = array("value1", "value2", "value3")
and I want to merge that array with an associative array set up like:
$associative_array = array(array("filename" => "value4"), array("filename" => "value5"), array("filename" => "value6"))
, so each numeric key in the associative array houses an extra array set.
What would be nice to do is something like:
$associative_array = array_merge(
[combine $basic_array into temp_array set up with same
structure of $associative_array, and add $basic_array
values into temp_array]
, $associative_array
);
It obviously would depend on what combination, if any, of array manipulation functions could copy the $associative_array structure on the fly, and fill the corresponding keys in each sub-array with values of the $basic_array, and then merge them.
I'm doing this because I want to de-dupe everything in the basic_array with the associative_array.
I'm currently doing this:
$manual_additions_filenames = array("vtlcvsp.pdf", "vtp.pdf", "vtpsai.pdf", "2990-2.pdf", "2990-8.pdf", "vtxbrl.zip", "vtfrisp.pdf", "vtp.pdf", "vtpsai.pdf", "1939-2.pdf", "cashcollateral.pdf", "cashreserves.pdf");
$associative_array_filenames = array(); //dummy one-dimensional array to store values in filename key of associative array
foreach ($associative_array as $key => $field_array)
{
$associative_array_filenames[] = $field_array["filename"];
} //pull filename and put into one-dimensional array
$manual_additions = array_diff(
array_unique($manual_additions_filenames), $associative_array_filenames
); //compare, to get list of unique filenames to be tacked on
foreach ($manual_additions as $value)
{
$associative_array[]["filename"] = $value;
}
All the native php array functions are designed to eliminate all these foreach loops, or so I thought, so I'd love to clean this crap up.