2017-02-17 3 views
-1

ich vor dem Array zusätzliche Schlüssel einfügen möchte, wenn Schlüssel vorhanden ist und Array ist nicht mehrdimensionale zum Beispiel:php multidimentional arrray iterativ recursevely

Array 
(
    [0] => Array 
     (
      [_key_] => Array 
       (
        [0] => Array 
         (
          [pub-id-type] => pmid 
          [value] => 25588809 
         ) 

        [1] => Array 
         (
          [pub-id-type] => pmc 
          [value] => 4302133 
         ) 

        [2] => Array 
         (
          [pub-id-type] => publisher-id 
          [value] => 1008 
         ) 

        [3] => Array 
         (
          [pub-id-type] => doi 
          [value] => 10.1186/s12885-015-1008-4 
         ) 

        [type_s] => article-id 
        [id] => 58a6eeedeab2f 
       ) 

     ) 

Ich mag:

Array 
(
    [0] => Array 
     (
      [_key_] => Array 
       (
[0]=>array(
        [0] => Array 
         (
          [pub-id-type] => pmid 
          [value] => 25588809 
         ) 

        [1] => Array 
         (
          [pub-id-type] => pmc 
          [value] => 4302133 
         ) 

        [2] => Array 
         (
          [pub-id-type] => publisher-id 
          [value] => 1008 
         ) 

        [3] => Array 
         (
          [pub-id-type] => doi 
          [value] => 10.1186/s12885-015-1008-4 
         ) 

        [type_s] => article-id 
        [id] => 58a6eeedeab2f 
       ) 
     ) 
) 

rekursiv util n depath von _Key_ wird gefunden.

+0

was Sie gewünschte Array für diese oben ein? –

Antwort

0

Das Layout ist nicht die beste, aber howerver ...

versuchen diese:

if(is_array($arr[0][_key_])) 
{ 
    $tmp = $arr[0][_key_]; 
    unset($arr[0][_key_]); 
    $arr[0][_key_][] = $tmp; 
}