Sample Output
Array
(
    [0] => Array
        (
            [file] => script.php
            [line] => 18
            [function] => query_wrapper
            [args] => Array
                (
                    [0] => SELECT * FROM msg WHERE id=abc
                )
        )

    [1] => Array
        (
            [file] => script.php
            [line] => 25
            [function] => get_message
            [args] => Array
                (
                    [0] => abc
                )
        )

    [2] => Array
        (
            [file] => script.php
            [line] => 28
            [function] => foo
            [args] => Array
                (
                )
        )
)
Practical Application
<?php
function generate_backtrace($bt_array)
{
    
// reverse array so we move from start to finish
    
rsort($bt_array);

    
$str '';
    foreach (
$bt_array as $entries) {
        
$str .= "{$entries['file']}:{$entries['line']} {$entries['function']}(".implode(', '$entries['args']).")\n";
    }

    return 
$str;
}
?>
End Result
script.php:41 foo()
script.php:38 get_message(abc)
script.php:31 query_wrapper(SELECT * FROM msg WHERE id=abc)