Tos Web Developer provides insights, tutorials, and advice around topics including content strategy, design, Drupal Development, Drupal Custom Module Development, Drupal 8 Custom themes, PHP, Server, Twig, and more

Que 3. Write a function which will take $arr as an argument and output
the all the keys as output

$array = array(
    '1' => array(
        '2,3,4' => array(
            '6,7' => array(
                '8,9' => array()
            )
        )
    )
 )
);
Output will be something like : 1,2,3,4,6,7...

ANSWER OF QUESTION: 1

  <?php  
 $array = array(  
   '1' => array(  
     '2,3,4' => array(  
       '6,7' => array(  
         '8,9' => array(  
           '10,11,12' => array()  
         )  
       )  
     )  
   )  
 );  
 function array_keys_multi(array $array)  
 {  
   $keys = array();  
   foreach ($array as $key => $value) {  
     $keys[] = $key;  
     if (is_array($array[$key])) {  
       $keys = array_merge($keys, array_keys_multi($array[$key]));  
     }  
   }  
   return $keys;  
 }  
 $aa = array_keys_multi($array);  
 foreach ($aa as $value) {  
   echo "$value,";  
 }  
 ?>   


ANSWER OF QUESTION: 2

  <?php  
 $array = array(  
   '1' => array(  
     '2,3,4' => array(  
       '6,7' => array(  
         '8,9' => array(  
           '10,11,12' => array()  
         )  
       )  
     )  
   )  
 );  
 pkeys($array);  
 function pkeys($a)  
 {  
   foreach ($a as $key => $value) {  
     print $key . ',';  
     if (is_array($value)) {  
       pkeys($value);  
     }  
   }  
 }  
 ?>   

No comments:

Post a Comment

| Designed And Blog Post by www.toswebdeveloper.com