Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PHP Exercises : Get the names of the functions of a module

PHP : Exercise-29 with Solution

Write a PHP script to get the names of the functions of a module.

Note : Find XML, JSON functions

Sample Solution: -

PHP Code:

<?php
print_r(get_extension_funcs("JSON"));
echo "\n";
print_r(get_extension_funcs("XML"))."\n";
?>

Sample Output:

Array                                                       
(                                                           
    [0] => json_encode                                      
    [1] => json_decode                                      
    [2] => json_last_error                                  
    [3] => json_last_error_msg                              
)                                                           
                                                            
Array                                                       
(                                                           
    [0] => xml_parser_create                                
    [1] => xml_parser_create_ns                             
    [2] => xml_set_object                                   
    [3] => xml_set_element_handler                          
    [4] => xml_set_character_data_handler                   
    [5] => xml_set_processing_instruction_handler           
    [6] => xml_set_default_handler                          
    [7] => xml_set_unparsed_entity_decl_handler
	[8] => xml_set_notation_decl_handler                    
    [9] => xml_set_external_entity_ref_handler              
    [10] => xml_set_start_namespace_decl_handler            
    [11] => xml_set_end_namespace_decl_handler              
    [12] => xml_parse                                       
    [13] => xml_parse_into_struct                           
    [14] => xml_get_error_code                              
    [15] => xml_error_string                                
    [16] => xml_get_current_line_number                     
    [17] => xml_get_current_column_number                   
    [18] => xml_get_current_byte_index                      
    [19] => xml_parser_free                                 
    [20] => xml_parser_set_option                           
    [21] => xml_parser_get_option                           
    [22] => utf8_encode                                     
    [23] => utf8_decode                                     
)

Flowchart:

Flowchart: Get the names of the functions of a module

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to get the directory path used for temporary files.
Next: Write a PHP script to get the time of the last modification of the current page.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



PHP: Tips of the Day

How to Sort Multi-dimensional Array by Value?

Try a usort, If you are still on PHP 5.2 or earlier, you'll have to define a sorting function first:

Example:

function sortByOrder($a, $b) {
    return $a['order'] - $b['order'];
}

usort($myArray, 'sortByOrder');

Starting in PHP 5.3, you can use an anonymous function:

usort($myArray, function($a, $b) {
    return $a['order'] - $b['order'];
});

And finally with PHP 7 you can use the spaceship operator:

usort($myArray, function($a, $b) {
    return $a['order'] <=> $b['order'];
});

To extend this to multi-dimensional sorting, reference the second/third sorting elements if the first is zero - best explained below. You can also use this for sorting on sub-elements.

usort($myArray, function($a, $b) {
    $retval = $a['order'] <=> $b['order'];
    if ($retval == 0) {
        $retval = $a['suborder'] <=> $b['suborder'];
        if ($retval == 0) {
            $retval = $a['details']['subsuborder'] <=> $b['details']['subsuborder'];
        }
    }
    return $retval;
});

If you need to retain key associations, use uasort() - see comparison of array sorting functions in the manual

Ref : https://bit.ly/3i77vCC