Hi everyone, I have a huge array returning as search results, and I want to do the following:
Go through the array and for each record with the same "spubid" add the following / vals switches: "sfirst, smi, slast" to the member of the parent array in this case, $ a [0]. Thus, the result will leave $ a [0] in tact, but adds the values ββfrom sfirst, smi and slast from other members of the array to it (since they all have the same "spubid"). I think adding the key value (1, 2, 3) to the associated key (sfirst1 => "J.", smi1 => "F.", Slast1 => "Kennedy") will be fine. Then I would like to DROP (unset ()) the remaining members of the array with this "spubid". Here is a simplified example of an array that I am returning, and in this example all entries have the same "spubid":
Array (
[0] =>
Array (
[spubid] => A00502
[sfirst] => J.
[smi] => A.
[slast] => Doe
[1] =>
Array (
[spubid] => A00502
[sfirst] => J.
[smi] => F.
[slast] => Kennedy
[2] =>
Array (
[spubid] => A00502
[sfirst] => B.
[smi] => F.
[slast] => James
[3] =>
Array (
[spubid] => A00502
[sfirst] => S.
[smi] => M.
[slast] => Williamson
)
)
, KEEP $a [0], = > (sfirst $key, smi $key, slast $key) "sfirst, smi, slast" "" $a [1] - [3].
, IDEAL:
Array (
[0] =>
Array (
[spubid] => A00502
[sfirst] => J.
[smi] => A.
[slast] => Doe
[sfirst1] => J.
[smi1] => F.
[slast1] => Kennedy
[sfirst2] => B.
[smi2] => F.
[slast2] => James
[sfirst3] => S.
[smi3] => M.
[slast3] => Williamson
)
)
, , "spubid" , 99% , .
*** UPDATE
, , , , , . Chacha102 zombat, " " A LOT , , . , :
[spubid] => A00680
[bactive] => t
[bbatch_import] => t
[bincomplete] => t
[scitation_vis] => I,X
[dentered] => 2009-08-03 12:34:14.82103
[sentered_by] => pubs_batchadd.php
[drev] => 2009-08-03 12:34:14.82103
[srev_by] => pubs_batchadd.php
[bpeer_reviewed] => t
[sarticle] => A case study of bora-driven flow and density changes on the Adriatic shelf (January 1987)
.
.
.
.
.
40 , . , , , , , . ( ) , , , .
**** :
, . , .
:
$apubs_final = array();
$spubid = NULL;
$ipub = 0;
foreach($apubs as $arec)
{
if($spubid != $arec['spubid'])
{
$ipub++;
$apubs_final[$ipub] = $arec;
$iauthor = 0;
$spubid = $arec['spubid'];
}
$iauthor++;
$apubs_final[$ipub]['authors'][$iauthor]['sauthor_first'] = $arec['sfirst'];
}
, , / !