2

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'"
Lomtrur
  • 1,703
  • 2
  • 19
  • 35
rm_beginners
  • 164
  • 5

1 Answers1

1

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)
}
designer132
  • 131
  • 7
  • thanks for the code I need to convert into a single array first I use these code function array_flatten($array) { if (!is_array($array)) { return FALSE; } $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result = array_merge($result, array_flatten($value)); } else { $result[$key] = $value; } } return $result; } from this link: https://stackoverflow.com/questions/6785355/convert-multidimensional-array-into-single-array – rm_beginners Oct 10 '19 at 01:56