php - how to display 2 different array in single array using for loop -


my output :

array (     [0] => array         (             [0] => array                 (                     [no] => 316198                     [name] => uma                 )              [1] => array                 (                     [0] => array                         (                             [totavg] => 3.0403                             [tot] => 20.2023                             [id] => 27                             [pid] => 710600                             [adr] => local                             [photo] => 123.png                             [date] => 19930-01-06 05:40                         )                  )          )  ) 

and want show :

{     "no": "316198",     "name": "uma",     "totavg": "3.0403",     "tot": "20.2023",     "id": "27",     "pid": "710600",     "adr": "local",     "photo": "123.png",     "date": "19930-01-06 05:40 am" } 

how can it?

use array_walk_recursive() flatten array , use json_encode() create json representation of array:

$result = array(); array_walk_recursive($array, function($v) use (&$result) { $result[] = $v; }); echo json_encode($result, json_pretty_print); 

if know key names of sub-arrays beforehand, use array_merge() shown in other answers, solutions fail if array nested 1 level deeper, or if positions of sub-arrays aren't known beforehand.

output:

[     316198,     "uma",     3.0403,     20.2023,     27,     710600,     "local",     "123.png",     "19930-01-06 05:40 am" ] 

demo


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -