How to convert single record array to ng-init format of AngularJS?

Viewed 64

I am using the php array to put in ng-init of AngularJS.

PHP array:

Array
(
    [0] => Array
        (
            [username] => admin
            [email] => admin@gmail.com
        )

)

AngularJS ng-init:

How to convert the output to:

"username='admin';email='admin@gmail.com'"
1 Answers

not tested but should work

function convert_array($arr){
    $tmp_arr=array();
    foreach($arr as $key=>$value){
        $tmp_arr[]=$key."='".$value."'";
    }
    return join(';',$tmp_arr)
}
Related