Php array merging problem

1 json data is string, but the data type is string.
2)); ciyu is $ciyu=array ("saoci" = > array) ("rookie tutorial", " master"
I want to merge $data and $ciyu into one array (multi-dimensional array)

Php
Mar.24,2021

the home page should first convert $data into an array json_decode ($data,true)
then use the php built-in function array_merge ($ciyu,$data)
, but your $data must also be a secondary array, if not you can use array_push ()


print ($data. the array cannot be output with print, it can be output with print_r, and cannot be used after the array. Concatenate strings

$data = '{"a":"haha", "b":"hehe"}';
$saoci = array("saoci"=>array("",""));

$data= json_decode($data,true);

var_dump($data);
$data=array_merge($data,$saoci);
print_r($data);

output:

array (size=2)
  'a' => string 'haha' (length=4)
  'b' => string 'hehe' (length=4)
Array ( [a] => haha [b] => hehe [saoci] => Array ( [0] =>  [1] =>  ) )
Menu