I have the following array:
Array
(
[0] => James
[1] => Mike
[2] => Liam
[3] => Shantel
[4] => Harry
)
Array
(
[0] => Green
[1] => Blue
[2] => Yellow
[3] => Purple
[4] => Red
)
How can I get these two arrays into a JSON object?
So this should be the expected output:
{"James":"Green","Mike":"Blue","Liam":"Yellow","Shantel":"Purple"}
This is what I tried doing but I'm getting a totally different output:
$final = array();
$names = ['James', 'Mike', 'Liam', 'Shantel', 'Harry']
$colors = ['Green', 'Blue', 'Yellow', 'Purple', 'Red']
for ($i = 0; $i <= 4; $i++) {
$final[] = array_push($final, $names[$i], $colors[$i]);
}
What am I doing wrong here?